{"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/open-computer/services/extensions/visible-bash.ts#L187-L223","documentation":"Thrown by visible-bash when the spawned command completes with realExitCode that is neither 0 nor null. realExitCode is read from a captured exit-code file (falling back to the spawn exit code). The thrown message includes the truncated stdout+stderr ('text'), so the failure cause is visible inline. This is the normal non-zero-exit path.","triggerScenarios":"Any shell command that exits non-zero: failing tests, type errors, missing binaries (127), permission denied (126), segfault (139), or a command that prints errors then exits 1.","commonSituations":"tsc/lint failing on the diff; a test suite with a failing assertion; command not found because PATH differs in the spawn environment; permission bits on a script; OOM kill (exit code 137).","solutions":["Read the captured 'text' in the message — it contains the command's stderr/stdout explaining the failure.","Fix the underlying command failure (resolve the type/test/build error) rather than suppressing.","If a non-zero exit is expected/acceptable, wrap the command with `|| true` or check exit code explicitly.","Verify the spawn environment PATH has the required binaries."],"exampleFix":"// before — non-zero exit throws\nbash({ command: \"npm test\" });\n\n// after — tolerate expected non-zero\nbash({ command: \"npm test || true\" });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const { content } = await bash({ command });\n} catch (e) {\n  // e.message includes the command's truncated stdout/stderr + exit code\n  if (/exited with code/.test(e.message)) {\n    reportFailure(e.message);\n    return;\n  }\n  throw e;\n}","preventionTips":["Read the captured text in the error — it contains the failing command's output.","Fix the underlying command failure rather than suppressing the exit code.","Append `|| true` only when a non-zero exit is genuinely acceptable."],"tags":["mcp-tool","shell","exit-code","visible-bash","process-control"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}