MCPcopy
hub / github.com/go-task/task / runDeferred

Method runDeferred

task.go:340–362  ·  view source on GitHub ↗
(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8)

Source from the content-addressed store, hash-verified

338}
339
340func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8) {
341 ctx, cancel := context.WithCancel(context.Background())
342 defer cancel()
343
344 cmd := t.Cmds[i]
345 cache := &templater.Cache{Vars: vars}
346 extra := map[string]any{}
347
348 if deferredExitCode != nil && *deferredExitCode > 0 {
349 extra["EXIT_CODE"] = fmt.Sprintf("%d", *deferredExitCode)
350 }
351
352 // Resolve template with secrets masked for logging
353 cmd.LogCmd = templater.MaskSecretsWithExtra(cmd.Cmd, vars, extra)
354 cmd.Cmd = templater.ReplaceWithExtra(cmd.Cmd, cache, extra)
355 cmd.Task = templater.ReplaceWithExtra(cmd.Task, cache, extra)
356 cmd.If = templater.ReplaceWithExtra(cmd.If, cache, extra)
357 cmd.Vars = templater.ReplaceVarsWithExtra(cmd.Vars, cache, extra)
358
359 if err := e.runCommand(ctx, t, call, i); err != nil {
360 e.Logger.VerboseErrf(logger.Yellow, "task: ignored error in deferred cmd: %s\n", err.Error())
361 }
362}
363
364func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *Call, i int) error {
365 cmd := t.Cmds[i]

Callers 1

RunTaskMethod · 0.95

Calls 6

runCommandMethod · 0.95
MaskSecretsWithExtraFunction · 0.92
ReplaceWithExtraFunction · 0.92
ReplaceVarsWithExtraFunction · 0.92
VerboseErrfMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected