{"record":{"id":"0b7e4967be95630b","repo":"Hmbown/CodeWhale","slug":"screencapture-exited-r-code-r-stderr-trim-slice-0-300","errorCode":null,"errorMessage":"screencapture exited ${r.code}: ${r.stderr.trim().slice(0, 300)}","messagePattern":"screencapture exited (.+?): (.+?)","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"critical","filePath":"crates/tui/plugins/computer-use/src/backends/darwin.mjs","lineNumber":548,"sourceCode":"    // mis-target every later coordinate. A window capture ignores `display`.\n    let displays = null;\n    if (!window) {\n      displays = await displayInfo();\n      if (disp != null && disp !== \"all\" && !displays.some((x) => x.index === disp)) {\n        throw new ExecError(`no display ${disp}; have [${displays.map((x) => x.index).join(\", \")}] — screenshot takes the display index from list_displays, not its id`);\n      }\n    }\n    if (window) args.push(\"-o\", \"-l\", String(window.window_id));\n    else if (disp && disp !== \"all\") args.push(\"-D\", String(disp));\n    if (region) {\n      if (!region.every((n) => Number.isFinite(n) && n >= 0) || region.length !== 4) {\n        throw new ExecError(\"region must be [x, y, w, h] in screen points\");\n      }\n      args.push(\"-R\", region.join(\",\"));\n    }\n    args.push(file);\n    const r = await runL(\"screencapture\", args, { timeoutMs: 20_000 });\n    if (r.code !== 0) throw new ExecError(`screencapture exited ${r.code}: ${r.stderr.trim().slice(0, 300)}`, r);\n    await fitRasterToBudget(file);\n    const stat = fs.statSync(file);\n    displays ??= await displayInfo();\n    const d = displays.find((x) => x.index === (disp === \"all\" ? 1 : disp)) ?? displays[0];\n    const scale = d?.scale ?? 1;\n    state.lastRaster = {\n      file,\n      ...(window ? { app_ref, window_index: window_id ?? 0 } : {}),\n      bytes: stat.size,\n      display: disp ?? 1,\n      // Region and window rasters describe that rect, not the whole display.\n      // The PNG header is the pixel ground truth; scale is derived from\n      // pixels/points below so Retina and mixed-DPI stay exact.\n      points: window?.points ?? (region ? { x: region[0], y: region[1], w: region[2], h: region[3] } : d?.points ?? null),\n      pixels: imagePixels(file),\n      scale: d?.scale ?? 1,\n      capturedAt: new Date().toISOString(),\n    };","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/darwin.mjs#L530-L566","documentation":"The darwin backend invokes the macOS `screencapture` CLI (20s timeout). If it exits with a non-zero status, the backend throws an ExecError embedding the exit code and up to 300 chars of stderr. This is a wrapper over OS-level capture failure — permission, session, or resource issues — not a validation error.","triggerScenarios":"Running without Screen Recording TCC permission (System Settings > Privacy & Security > Screen Recording); running in an SSH/headless session without a WindowServer; screencapture failing on an invalid -R rect or display; the screen-locked/secure-input state blocking capture.","commonSituations":"First run of the app after install where the permission prompt was dismissed; CI runners without a GUI login; kiosk/VNC environments where the window server is unavailable.","solutions":["Grant Screen Recording permission to the host app/terminal in System Settings > Privacy & Security > Screen Recording, then restart it.","Run inside a logged-in GUI session (not SSH/headless) where WindowServer is available.","Read the embedded stderr in the error message for the specific screencapture failure reason.","Unlock the screen and ensure a display is attached before retrying."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await screenshot() } catch (e) {\n  if (String(e.message).startsWith(\"screencapture exited\")) {\n    // log stderr from the message; usually TCC screen-recording permission\n    console.error(\"Screen Recording permission or GUI session missing:\", e.message);\n  } else throw e;\n}","preventionTips":["Grant Screen Recording permission to the host app on first run (TCC) and restart it.","Run only inside a logged-in GUI session, not SSH/headless/CI without WindowServer.","Keep the 20s timeout in mind; don't issue overlapping captures."],"tags":["macos","screencapture","permissions","process-exit"],"backgroundTag":"command-not-found","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}