Mintplex-Labs/anything-llm · error · Error
Command exited with code
Error message
${text}
Command exited with code ${realExitCode} What it means
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.
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
Example fix
# before: grep exits 1 when nothing matches -> tool error
{ "command": "grep -q ready /var/log/app.log" }
# after: treat no-match as a branch, not a failure
{ "command": "if grep -q ready /var/log/app.log; then echo READY; else echo NOT_READY; fi" } Defensive patterns
Strategy: try-catch
Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Command aborted
- Command timed out after
- click requires coordinates
- EFI firmware not found
- EFI vars template not found
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/0adb0a749c6358fe.
Report an issue: GitHub.
Appendix: source
Thrown at open-computer/services/extensions/visible-bash.ts:205
throw new Error(
output
? `${truncateOutput(output)}\n\nCommand aborted`
: "Command aborted"
);
}
if (timedOut) {
throw new Error(
output
? `${truncateOutput(output)}\n\nCommand timed out after ${timeout} seconds`
: `Command timed out after ${timeout} seconds`
);
}
const text = truncateOutput(output) || "(no output)";
if (realExitCode !== 0 && realExitCode !== null) {
throw new Error(`${text}\n\nCommand exited with code ${realExitCode}`);
}
return { content: [{ type: "text", text }], details: {} };
} finally {
cleanup();
}
},
});
}
function truncateOutput(raw: string): string {
if (raw.length <= MAX_OUTPUT_BYTES && raw.split("\n").length <= MAX_OUTPUT_LINES) {
return raw;
}
let text = raw;
if (text.length > MAX_OUTPUT_BYTES) {
text = text.slice(-MAX_OUTPUT_BYTES);View on GitHub (pinned to 3aec848f28)