{"record":{"id":"2ea612e99c50c60e","repo":"golang/go","slug":"bad-exit-code-v-in-q","errorCode":null,"errorMessage":"bad exit code: %v (in %q)","messagePattern":"bad exit code: (.+?) \\(in %q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/go_android_exec/main.go","lineNumber":286,"sourceCode":"\tb := f.buf.Bytes()\n\tdefer f.buf.Reset()\n\tmatch := f.exitRe.FindSubmatch(b)\n\tif len(match) < 2 || match[1] == nil {\n\t\t// Not a full match. Flush.\n\t\tif _, err := f.w.Write(b); err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, fmt.Errorf(\"no exit code (in %q)\", string(b))\n\t}\n\n\t// Parse the exit code.\n\tcode, err := strconv.Atoi(string(match[1]))\n\tif err != nil {\n\t\t// Something is malformed. Flush.\n\t\tif _, err := f.w.Write(b); err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, fmt.Errorf(\"bad exit code: %v (in %q)\", err, string(b))\n\t}\n\treturn code, nil\n}\n\n// pkgPath determines the package import path of the current working directory,\n// and indicates whether it is\n// and returns the path to the package source relative to $GOROOT (or $GOPATH).\nfunc pkgPath() (importPath string, isStd bool, modPath, modDir string, err error) {\n\terrorf := func(format string, args ...any) (string, bool, string, string, error) {\n\t\treturn \"\", false, \"\", \"\", fmt.Errorf(format, args...)\n\t}\n\tgoTool, err := goTool()\n\tif err != nil {\n\t\treturn errorf(\"%w\", err)\n\t}\n\tcmd := exec.Command(goTool, \"list\", \"-e\", \"-f\", \"{{.ImportPath}}:{{.Standard}}{{with .Module}}:{{.Path}}:{{.Dir}}{{end}}\", \".\")\n\tout, err := cmd.Output()\n\tif err != nil {","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/go_android_exec/main.go#L268-L304","documentation":"Returned by exitCodeFilter.Finish (main.go:286) when the regex matched and captured an exit-code group, but strconv.Atoi failed to parse it as an integer. The captured text was present but not numeric, indicating malformed output from the device.","triggerScenarios":"The exit-code regex matched text that is not a pure integer — e.g., the regex captured trailing characters, or the device/process emitted a non-numeric value where the exit code was expected. Generally points to a corrupted or partially-overwritten marker line.","commonSituations":"Output interleaving/concurrency garbled the exit marker line; a custom test harness prints text that matches the regex shape but with non-numeric content; terminal control sequences embedded in the captured group.","solutions":["Examine the quoted buffer in the error — it shows exactly what was captured.","Reduce output interleaving: run with -p 1 (no parallel tests) to see if the marker stabilizes.","Ensure no test prints bytes that mimic the exit-code marker format.","If using a custom runner, make sure it emits the canonical 'exit status <int>' line."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := run.onDevice(...); err != nil {\n    if strings.Contains(err.Error(), \"bad exit code\") {\n        // output interleaving; retry with -p 1\n        return rerunSerial()\n    }\n    return err\n}","preventionTips":["Run tests serially (-p 1) when output interleaving corrupts the exit marker.","Ensure no test prints bytes matching the exit-code marker format.","Use the canonical 'exit status <int>' line in custom runners."],"tags":["android","adb","go-test","exit-code","parsing"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}