pranshuparmar/witr · error
completed with exit code %d
Error message
completed with exit code %d
What it means
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.
Source
Thrown at internal/app/app.go:243
// Emit JSON array for multi-target
if flags.json && multiMode {
indented := make([]string, len(jsonResults))
for i, r := range jsonResults {
lines := strings.Split(r, "\n")
for j := range lines {
if j > 0 {
lines[j] = " " + lines[j]
}
}
indented[i] = " " + strings.Join(lines, "\n")
}
fmt.Fprintf(outw, "[\n%s\n]\n", strings.Join(indented, ",\n"))
}
if highestExit > ExitOK {
cmd.SilenceErrors = true
return withExitCode(highestExit, fmt.Errorf("completed with exit code %d", highestExit))
}
return nil
}
func boolFlag(cmd *cobra.Command, name string) bool {
v, _ := cmd.Flags().GetBool(name)
return v
}
// flagTakesValue reports whether a raw argv token names a non-boolean flag
// whose value is the following token (e.g. "--config foo"). It lets the
// order-preserving parser take flag-arity from cobra's flag set instead of
// assuming every non-target flag is boolean — so a future string-valued flag
// won't have its value mistaken for a target.
func flagTakesValue(cmd *cobra.Command) func(string) bool {
return func(arg string) bool {
if strings.Contains(arg, "=") {
return false // value is attached: --flag=valueView on GitHub (pinned to dc4fa1da82)
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.
Defensive patterns
Strategy: try-catch
Try / catch
err := rootCmd.Execute()
if err != nil {
if strings.Contains(err.Error(), "completed with exit code") {
// summary failure: individual target errors were already printed
os.Exit(exitCodeFromMessage(err.Error()))
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- must specify --pid, --port, --file, --container, or a proces
- no matching process found
- no container found matching %q
AI-assisted analysis of pranshuparmar/witr@dc4fa1da82 (2026-09-01).
Data as JSON: /api/errors/3d6d944328220026.
Report an issue: GitHub.