{"record":{"id":"a446337eae74eb58","repo":"golang/go","slug":"cmdline-0-err","errorCode":null,"errorMessage":"${cmdline[0]}: ${err}","messagePattern":"\\$\\{cmdline\\[0\\]\\}: \\$\\{err\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/shell.go","lineNumber":667,"sourceCode":"\tstart := time.Now()\n\terr = cmd.Run()\n\tif a != nil && a.json != nil {\n\t\taj := a.json\n\t\taj.Cmd = append(aj.Cmd, joinUnambiguously(cmdline))\n\t\taj.CmdReal += time.Since(start)\n\t\tif ps := cmd.ProcessState; ps != nil {\n\t\t\taj.CmdUser += ps.UserTime()\n\t\t\taj.CmdSys += ps.SystemTime()\n\t\t}\n\t}\n\n\t// err can be something like 'exit status 1'.\n\t// Add information about what program was running.\n\t// Note that if buf.Bytes() is non-empty, the caller usually\n\t// shows buf.Bytes() and does not print err at all, so the\n\t// prefix here does not make most output any more verbose.\n\tif err != nil {\n\t\terr = errors.New(cmdline[0] + \": \" + err.Error())\n\t}\n\treturn buf.Bytes(), err\n}\n\n// joinUnambiguously prints the slice, quoting where necessary to make the\n// output unambiguous.\n// TODO: See issue 5279. The printing of commands needs a complete redo.\nfunc joinUnambiguously(a []string) string {\n\tvar buf strings.Builder\n\tfor i, s := range a {\n\t\tif i > 0 {\n\t\t\tbuf.WriteByte(' ')\n\t\t}\n\t\tq := strconv.Quote(s)\n\t\t// A gccgo command line can contain -( and -).\n\t\t// Make sure we quote them since they are special to the shell.\n\t\t// The trimpath argument can also contain > (part of =>) and ;. Quote those too.\n\t\tif s == \"\" || strings.ContainsAny(s, \" ()>;\") || len(q) > len(s)+2 {","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/shell.go#L649-L685","documentation":"Constructed in (*shell).run in cmd/go/internal/work/shell after a child process (compiler, linker, swig, pkg-config, etc.) exits with a non-zero status. The shell wraps the raw error (typically an *exec.ExitError like \"exit status 1\") by prefixing it with the invoked program's name, so the user can tell which tool failed. The message template is \"<prog>: <underlying error>\". This is the go command's standard way of attributing subprocess failures.","triggerScenarios":"Any subprocess the go command spawns returning non-zero: a compiler error (gc/gccgo), a linker failure, swig error, pkg-config error, asm failure, or a custom -gcflags/-ldflags tool. The wrapped error carries the program's argv[0]; buf.Bytes() (captured stderr) is usually shown by the caller instead of this string.","commonSituations":"Compilation errors (syntax, type errors). Missing include/library paths in CGo. Out-of-memory or signal kills during large builds. A tool invoked via -gcflags/-ldflags that does not exist or is not executable. Disk full or permission denied on output files.","solutions":["Read the lines printed just above this error — the subprocess's stderr (buf.Bytes()) holds the real cause; the \"<prog>: exit status N\" line is just the attribution.","Re-run the failing go command with -x to see the exact subprocess invocation, then run that command manually to reproduce.","Fix the underlying compiler/linker/tool error reported in the captured output.","If stderr was empty, check for signal kills (OOM), missing binaries (PATH), or permission issues on output paths."],"exampleFix":"# before\n$ go build ./...\n# (no compiler output visible)\ncompile: exit status 1\n\n# after — re-run with -x to see and reproduce the exact failing command\n$ go build -x ./... 2>&1 | tail -20\n$ /usr/local/go/pkg/tool/linux_amd64/compile -o /tmp/_o *.go   # reproduce & fix","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure all tools the build will invoke exist and are executable.\nfunc ensureTools(tools []string) error {\n    for _, t := range tools {\n        if _, err := exec.LookPath(t); err != nil {\n            return fmt.Errorf(\"build tool %q not found in PATH: %w\", t, err)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Always pair the wrapped error with captured stderr for context.\nout, err := sh.run(...)\nif err != nil {\n    return fmt.Errorf(\"%s failed: %w\\nstderr: %s\", prog, err, out)\n}","preventionTips":["Re-run failing builds with -x to capture the exact subprocess command.","Log captured stderr/stdout alongside the wrapped error.","Pre-flight check that compilers/swig/pkg-config exist on PATH before building."],"tags":["go-toolchain","subprocess","build","wrapper","diagnostic"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}