{"record":{"id":"0adb0a749c6358fe","repo":"Mintplex-Labs/anything-llm","slug":"text-command-exited-with-code-realexitcode","errorCode":null,"errorMessage":"${text}\n\nCommand exited with code ${realExitCode}","messagePattern":"(.+?)\n\nCommand exited with code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-computer/services/extensions/visible-bash.ts","lineNumber":205,"sourceCode":"          throw new Error(\n            output\n              ? `${truncateOutput(output)}\\n\\nCommand aborted`\n              : \"Command aborted\"\n          );\n        }\n\n        if (timedOut) {\n          throw new Error(\n            output\n              ? `${truncateOutput(output)}\\n\\nCommand timed out after ${timeout} seconds`\n              : `Command timed out after ${timeout} seconds`\n          );\n        }\n\n        const text = truncateOutput(output) || \"(no output)\";\n\n        if (realExitCode !== 0 && realExitCode !== null) {\n          throw new Error(`${text}\\n\\nCommand exited with code ${realExitCode}`);\n        }\n\n        return { content: [{ type: \"text\", text }], details: {} };\n      } finally {\n        cleanup();\n      }\n    },\n  });\n}\n\nfunction truncateOutput(raw: string): string {\n  if (raw.length <= MAX_OUTPUT_BYTES && raw.split(\"\\n\").length <= MAX_OUTPUT_LINES) {\n    return raw;\n  }\n\n  let text = raw;\n  if (text.length > MAX_OUTPUT_BYTES) {\n    text = text.slice(-MAX_OUTPUT_BYTES);","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/open-computer/services/extensions/visible-bash.ts#L187-L223","documentation":"Thrown by the visible-bash extension after the command completed: the wrapper wrote a non-zero exit code to the temp exitcode file, and realExitCode is neither 0 nor null. The error body is the command's captured output (truncated to the last 2000 lines / 256KB, or '(no output)') followed by 'Command exited with code N'. This is simply the terminal command failing, surfaced to the agent as a tool error.","triggerScenarios":"Any bash tool invocation whose command returns non-zero: compile errors, failing tests, 'command not found' (127), permission denied, grep with no matches (1), pip/npm install failures, etc. The exit code is the real one read back from the exitcode file, not the wrapper's.","commonSituations":"Agent-run builds/tests that legitimately fail; missing dependencies inside the VM; typo'd command names; scripts using set -e aborting on the first failed step.","solutions":["Read the output portion of the error — it contains the actual stderr/stdout that explains the non-zero code","Fix the underlying command failure (install the missing dependency, correct the typo, fix the failing test)","If a non-zero code is expected (e.g. grep no-match, diff differences), append '|| true' or 'exit 0' handling so the tool call succeeds while still printing the result","For scripts, echo a clear error message before exiting non-zero so the truncated output keeps the diagnostic"],"exampleFix":"# before: grep exits 1 when nothing matches -> tool error\n{ \"command\": \"grep -q ready /var/log/app.log\" }\n# after: treat no-match as a branch, not a failure\n{ \"command\": \"if grep -q ready /var/log/app.log; then echo READY; else echo NOT_READY; fi\" }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { const r = await bash.run(cmd); } catch (e) { const m = e.message.match(/\\n\\nCommand exited with code (-?\\d+)$/); if (m) { const code = Number(m[1]); /* use output text + code to branch (127 not found, 1 failed, ...) */ } else throw e; }","preventionTips":["Make commands print the cause before exiting non-zero — truncated output keeps the diagnosis","Wrap expected non-zero tools (grep, diff, test) with explicit if/else so they exit 0 with a status string","Parse the trailing 'Command exited with code N' suffix rather than stringifying the whole error when branching"],"tags":["bash","exit-code","process-output","open-computer"],"backgroundTag":"nonzero-exit-code","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}