{"record":{"id":"18cf768958963798","repo":"go-task/task","slug":"task-command-s-failed-s","errorCode":null,"errorMessage":"task: Command \"%s\" failed: %s","messagePattern":"task: Command \"(.+?)\" failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler.go","lineNumber":179,"sourceCode":"\tif result, ok := c.dynamicCache[*v.Sh]; ok {\n\t\treturn result, nil\n\t}\n\n\t// NOTE(@andreynering): If a var have a specific dir, use this instead\n\tif v.Dir != \"\" {\n\t\tdir = v.Dir\n\t}\n\n\tvar stdout bytes.Buffer\n\topts := &execext.RunCommandOptions{\n\t\tCommand: *v.Sh,\n\t\tDir:     dir,\n\t\tStdout:  &stdout,\n\t\tStderr:  c.Logger.Stderr,\n\t\tEnv:     e,\n\t}\n\tif err := execext.RunCommand(context.Background(), opts); err != nil {\n\t\treturn \"\", fmt.Errorf(`task: Command \"%s\" failed: %s`, opts.Command, err)\n\t}\n\n\t// Trim a single trailing newline from the result to make most command\n\t// output easier to use in shell commands.\n\tresult := strings.TrimSuffix(stdout.String(), \"\\r\\n\")\n\tresult = strings.TrimSuffix(result, \"\\n\")\n\n\tc.dynamicCache[*v.Sh] = result\n\t// Never print the resolved value of a secret variable, even in verbose mode\n\tlogResult := result\n\tif v.Secret {\n\t\tlogResult = \"*****\"\n\t}\n\tc.Logger.VerboseErrf(logger.Magenta, \"task: dynamic variable: %q result: %q\\n\", *v.Sh, logResult)\n\n\treturn result, nil\n}\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/go-task/task/blob/385e5ad92af02877b6d7cf9dcc963b5ed916e70a/compiler.go#L161-L197","documentation":"Task wraps any failure from running a shell command during dynamic variable evaluation (the `sh:` / `cmd:` variable sources) with this message, embedding the command string and the underlying exec error. It indicates that a command used to compute a task variable exited non-zero or could not be executed at all. The raw OS error is preserved via %s so the root cause (exit status, missing binary, permission) is visible in the wrapped text.","triggerScenarios":"A task's variable uses `sh:` (or `cmd:` on Windows) and the Compiler's dynamic variable handler executes it via execext.RunCommand; the command exits non-zero or fails to start. Raised in HandleDynamicVar while compiling task variables before the task runs.","commonSituations":"Referencing a nonexistent binary (e.g. `git` not installed), running a script that fails in CI but not locally, wrong working directory (Dir), missing environment variables expected by the command, or commands that print to stderr and return non-zero by design.","solutions":["Run the failing command manually in the task's directory to see the real error and fix the command or its inputs","Guard the command so it exits 0 when information is unavailable, e.g. `sh: git describe --tags || echo unknown`","Install the missing tool or fix PATH/Env so the command can be found","If the exit code is expected, capture it in the shell (e.g. `sh: cat file 2>/dev/null || true`)"],"exampleFix":"# before\nvars:\n  VERSION:\n    sh: git describe --tags\n# after\nvars:\n  VERSION:\n    sh: git describe --tags || echo v0.0.0","handlingStrategy":"try-catch","validationCode":"// check tools used by sh: variables exist before running\ncmds := [\"git\", \"make\"]\nfor _, c := range cmds {\n  if _, err := exec.LookPath(c); err != nil {\n    return fmt.Errorf(\"missing tool for task vars: %s\", c)\n  }\n}","typeGuard":null,"tryCatchPattern":"err := task.Run(ctx, t)\nif err != nil && strings.Contains(err.Error(), `Command \"`) && strings.Contains(err.Error(), \"failed\") {\n  // extract cmd + cause, decide: retry with fallback var or surface to user\n}","preventionTips":["Make every sh: variable command exit 0 with a sensible fallback (|| echo default)","Pin and document tool dependencies (git, jq, etc.) in your environment","Test Taskfiles in CI so failing variable commands surface early"],"tags":["shell","command-execution","variables"],"backgroundTag":"command-exit-nonzero","analyzedSha":"385e5ad92af02877b6d7cf9dcc963b5ed916e70a","analyzedAt":"2026-09-05T09:01:05.226Z","contentChangedAt":"2026-09-05T09:01:05.226Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}