{"record":{"id":"c66efda896af1f03","repo":"go-task/task","slug":"task-failed-to-get-variables-w","errorCode":null,"errorMessage":"task: failed to get variables: %w","messagePattern":"task: failed to get variables: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"task.go","lineNumber":428,"sourceCode":"\t\t\treturn nil\n\t\t}\n\n\t\tif e.Verbose || (!call.Silent && !cmd.Silent && !t.IsSilent() && !e.Taskfile.Silent && !e.Silent) {\n\t\t\te.Logger.Errf(logger.Green, \"task: [%s] %s\\n\", t.Name(), cmd.LogCmd)\n\t\t}\n\n\t\tif e.Dry {\n\t\t\treturn nil\n\t\t}\n\n\t\toutputWrapper := e.Output\n\t\tif t.Interactive {\n\t\t\toutputWrapper = output.Interleaved{}\n\t\t}\n\t\tvars, err := e.Compiler.FastGetVariables(t, call)\n\t\toutputTemplater := &templater.Cache{Vars: vars}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"task: failed to get variables: %w\", err)\n\t\t}\n\t\tstdOut, stdErr, closer := outputWrapper.WrapWriter(e.Stdout, e.Stderr, t.Prefix, outputTemplater)\n\n\t\terr = execext.RunCommand(ctx, &execext.RunCommandOptions{\n\t\t\tCommand:   cmd.Cmd,\n\t\t\tDir:       t.Dir,\n\t\t\tEnv:       env.Get(t),\n\t\t\tPosixOpts: slicesext.UniqueJoin(e.Taskfile.Set, t.Set, cmd.Set),\n\t\t\tBashOpts:  slicesext.UniqueJoin(e.Taskfile.Shopt, t.Shopt, cmd.Shopt),\n\t\t\tStdin:     e.Stdin,\n\t\t\tStdout:    stdOut,\n\t\t\tStderr:    stdErr,\n\t\t})\n\t\tif closeErr := closer(err); closeErr != nil {\n\t\t\te.Logger.Errf(logger.Red, \"task: unable to close writer: %v\\n\", closeErr)\n\t\t}\n\t\tif err != nil && timedOut(ctx, timeout) {\n\t\t\terr = timeout","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/go-task/task/blob/385e5ad92af02877b6d7cf9dcc963b5ed916e70a/task.go#L410-L446","documentation":"While executing a command, runCommand first fetches the task's variables via FastGetVariables; if that fails, the command can't be templated and this error wraps the underlying cause. It indicates the variable-compilation stage (including dynamic sh:/cmd: variables) failed before the command even ran.","triggerScenarios":"e.Compiler.FastGetVariables(t, call) returns an error during runCommand — typically because a dynamic (sh:/cmd:) variable inside the task or its dependencies failed to execute — right before wrapping writers for the command output.","commonSituations":"Dynamic variable commands failing (missing tools, non-zero exits), template compilation errors in variable resolution, or environment/directory problems making a variable's shell command fail. Usually the wrapped error points at the actual failing variable.","solutions":["Read the wrapped %w cause — fix the underlying variable error it reports (often a failing sh: command)","Test the dynamic variable's command manually in the task directory","Simplify variable definitions to isolate which variable fails compilation","Ensure required tools/env for the variable commands exist in the execution environment"],"exampleFix":"# before\nvars:\n  BRANCH:\n    sh: git rev-parse --abbrev-ref HEAD\n# after\nvars:\n  BRANCH:\n    sh: git rev-parse --abbrev-ref HEAD || echo unknown","handlingStrategy":"try-catch","validationCode":"// sanity-check dynamic variables before running the task\nfor _, v := range taskDef.Vars {\n  if v.Sh != \"\" {\n    if err := exec.Command(\"sh\", \"-c\", v.Sh).Run(); err != nil {\n      return fmt.Errorf(\"dynamic var fails: %w\", err)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"err := t.Run(ctx)\nif err != nil && strings.Contains(err.Error(), \"failed to get variables\") {\n  // unwrap %w cause, fix the failing variable, then retry\n  var inner error\n  errors.As(err, &inner)\n}","preventionTips":["Give every dynamic (sh:/cmd:) variable a non-zero-safe fallback","Keep variable commands simple and dependency-free where possible","Log the wrapped cause — the %w chain names the real failure"],"tags":["variables","compilation","shell"],"backgroundTag":"variable-resolution-failed","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"}