{"record":{"id":"3d6d944328220026","repo":"pranshuparmar/witr","slug":"completed-with-exit-code-d","errorCode":null,"errorMessage":"completed with exit code %d","messagePattern":"completed with exit code (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/app/app.go","lineNumber":243,"sourceCode":"\n\t// Emit JSON array for multi-target\n\tif flags.json && multiMode {\n\t\tindented := make([]string, len(jsonResults))\n\t\tfor i, r := range jsonResults {\n\t\t\tlines := strings.Split(r, \"\\n\")\n\t\t\tfor j := range lines {\n\t\t\t\tif j > 0 {\n\t\t\t\t\tlines[j] = \"  \" + lines[j]\n\t\t\t\t}\n\t\t\t}\n\t\t\tindented[i] = \"  \" + strings.Join(lines, \"\\n\")\n\t\t}\n\t\tfmt.Fprintf(outw, \"[\\n%s\\n]\\n\", strings.Join(indented, \",\\n\"))\n\t}\n\n\tif highestExit > ExitOK {\n\t\tcmd.SilenceErrors = true\n\t\treturn withExitCode(highestExit, fmt.Errorf(\"completed with exit code %d\", highestExit))\n\t}\n\treturn nil\n}\n\nfunc boolFlag(cmd *cobra.Command, name string) bool {\n\tv, _ := cmd.Flags().GetBool(name)\n\treturn v\n}\n\n// flagTakesValue reports whether a raw argv token names a non-boolean flag\n// whose value is the following token (e.g. \"--config foo\"). It lets the\n// order-preserving parser take flag-arity from cobra's flag set instead of\n// assuming every non-target flag is boolean — so a future string-valued flag\n// won't have its value mistaken for a target.\nfunc flagTakesValue(cmd *cobra.Command) func(string) bool {\n\treturn func(arg string) bool {\n\t\tif strings.Contains(arg, \"=\") {\n\t\t\treturn false // value is attached: --flag=value","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/pranshuparmar/witr/blob/dc4fa1da82d3e266fcbd928641b4f30b3077c64f/internal/app/app.go#L225-L261","documentation":"runApp aggregates the exit codes of per-target inspection runs into highestExit. When any target failed (any code above ExitOK), it silences cobra's own error printing and returns a synthetic 'completed with exit code N' error carrying the highest severity code so the process exits non-zero. This is a summary error, not a distinct failure — inspect the per-target output printed above it for the real cause.","triggerScenarios":"Running the tool with multiple targets (multiMode) where at least one target's inspection failed; the returned error's exit code equals the worst per-target code.","commonSituations":"Batch scripts checking many pids/ports where one target is stale or gone; CI jobs scanning a list of processes where a name no longer resolves; JSON batch runs where individual entries contain error objects.","solutions":["Read the per-target output/JSON entries printed before this error to find which target failed and why.","Fix or remove the failing target (stale pid, wrong container name, missing process).","In scripts, parse the exit code to distinguish partial failure from total failure.","Use --json and check each entry's error field programmatically."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := rootCmd.Execute()\nif err != nil {\n    if strings.Contains(err.Error(), \"completed with exit code\") {\n        // summary failure: individual target errors were already printed\n        os.Exit(exitCodeFromMessage(err.Error()))\n    }\n    fmt.Fprintln(os.Stderr, err)\n    os.Exit(1)\n}","preventionTips":["Pre-validate each target (pid alive, port listening, container running) before the batch run.","Use --json in multi-target runs and inspect per-entry error fields.","Treat this as a summary signal: always read per-target output for the root cause."],"tags":["cli","exit-code","batch-processing"],"backgroundTag":"batch-partial-failure-exit-code","analyzedSha":"dc4fa1da82d3e266fcbd928641b4f30b3077c64f","analyzedAt":"2026-09-01T12:17:08.767Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}