{"record":{"id":"adaa6187278ebdf9","repo":"moeru-ai/airi","slug":"json-stringify-result","errorCode":null,"errorMessage":"JSON.stringify(result)","messagePattern":"JSON\\.stringify\\(result\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/renderer/stores/tools/builtin/computer-use.ts","lineNumber":38,"sourceCode":"    invokers ??= createInvokers()\n    return invokers\n  }\n  return [\n    rawTool({\n      name: 'computer_use',\n      description: 'Control native desktop apps, inspect windows, capture screenshots, and use keyboard or mouse input. On macOS, call app.probePermissions before visual tasks. If screen_recording is missing, ask the user to grant permission; captures can contain only a blank background. Start with argv [\"invoke\", \"--help\"], then inspect command help. Pass each CLI argument separately. Use explicit window targets when available. Preserve failure_details and verified metadata: exitCode 0 does not prove the intended UI effect. Use computer_use_read_image to view screenshot artifact paths. This tool acts on the local computer.',\n      parameters: {\n        type: 'object',\n        properties: {\n          argv: { type: 'array', items: { type: 'string' }, description: 'AUV arguments beginning with invoke, excluding the executable name.' },\n        },\n        required: ['argv'],\n        additionalProperties: false,\n      },\n      execute: async (input) => {\n        const result = await client().run(input as { argv: string[] })\n        if (result.exitCode !== 0)\n          throw new Error(JSON.stringify(result))\n        return JSON.stringify(result)\n      },\n    }),\n    rawTool({\n      name: 'computer_use_read_image',\n      description: 'View a PNG or JPEG screenshot artifact produced by computer_use. Only files inside AIRI computer-use storage can be read. Select this tool together with computer_use for visual tasks.',\n      parameters: {\n        type: 'object',\n        properties: { path: { type: 'string', description: 'Absolute screenshot artifact path returned by computer_use.' } },\n        required: ['path'],\n        additionalProperties: false,\n      },\n      execute: async input => [{ type: 'image_url', image_url: { url: await client().readImage(input as { path: string }) } }],\n    }),\n  ]\n}\n","sourceCodeStart":20,"sourceCodeEnd":55,"githubUrl":"https://github.com/moeru-ai/airi/blob/438a067dde47aa0bdb46c2323d1fe293dc805218/apps/stage-tamagotchi/src/renderer/stores/tools/builtin/computer-use.ts#L20-L55","documentation":"The computer_use tool's execute callback throws the raw JSON-serialized command result whenever the shell command exits with a non-zero exit code. The stringified result (stdout, stderr, exitCode) becomes the error message; it is not a library bug but an intentional propagation of a failed command executed on the local machine via the computer-use client.","triggerScenarios":"client().run({ argv }) returns exitCode !== 0 — the executed argv refers to a missing binary, a command that failed (bad flags, non-zero exit path), or a sandboxed environment where the command cannot run.","commonSituations":"LLM agent issues computer_use with an invalid or unavailable command; permission or PATH differences inside the computer-use sandbox; command writes to stderr and exits non-zero (e.g. grep with no matches, diff on differing files).","solutions":["Inspect the thrown message (it is JSON); parse it and read stdout/stderr/exitCode to see the underlying command failure.","Fix the argv the agent/Caller passed: verify the binary exists in the computer-use environment and flags are valid.","If the command legitimately exits non-zero, catch the error and treat the parsed result as normal tool output instead of a hard failure.","Check the computer-use service/storage setup if commands that should succeed consistently fail."],"exampleFix":"// before\nexecute: async (input) => {\n  const result = await client().run(input as { argv: string[] })\n  if (result.exitCode !== 0)\n    throw new Error(JSON.stringify(result))\n  return JSON.stringify(result)\n}\n\n// after\nexecute: async (input) => {\n  const result = await client().run(input as { argv: string[] })\n  if (result.exitCode !== 0)\n    throw new Error(`computer_use failed (exit ${result.exitCode}): ${result.stderr || result.stdout}`)\n  return JSON.stringify(result)\n}","handlingStrategy":"try-catch","validationCode":"const known = ['ls','cat','pwd','echo']\nif (!known.includes(argv[0])) throw new Error(`command may not exist in computer-use env: ${argv[0]}`)","typeGuard":"function commandFailed(result: { exitCode: number }): boolean {\n  return result.exitCode !== 0\n}","tryCatchPattern":"try {\n  const out = await computerUseTool.execute({ argv })\n} catch (err) {\n  try {\n    const result = JSON.parse((err as Error).message)\n    console.error(`exit ${result.exitCode}: ${result.stderr}`)\n  } catch {\n    console.error(err)\n  }\n}","preventionTips":["Parse the error message as JSON to recover stdout/stderr/exitCode.","Constrain the agent's argv to commands known to exist in the computer-use environment.","Treat non-zero exit codes (grep, diff) as expected results, not fatal errors.","Verify PATH and sandbox permissions in the computer-use service config."],"tags":["shell","tool-call","exit-code","agent"],"backgroundTag":"command-not-found","analyzedSha":"438a067dde47aa0bdb46c2323d1fe293dc805218","analyzedAt":"2026-09-17T01:14:42.644Z","contentChangedAt":"2026-09-17T01:14:42.644Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}