{"record":{"id":"8386983f6a850105","repo":"Hmbown/CodeWhale","slug":"open-failed-r-stderr-trim-slice-0-200","errorCode":null,"errorMessage":"open failed: ${r.stderr.trim().slice(0, 200)}","messagePattern":"open failed: (.+?)","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/darwin.mjs","lineNumber":570,"sourceCode":"    const find = {};\n    if (pid) find.pid = pid; else if (bid) find.bundle_id = bid; else find.name = String(name).replace(/\\.app$/, \"\");\n    let p;\n    // Binding an already-running app must not ask LaunchServices to reopen\n    // it: reopen can raise windows even with open -g on some applications.\n    if (!urlArg) {\n      try { p = await native(\"app_info\", { app_ref: find, activate }); }\n      catch (error) {\n        if (!error.message.includes(\"application not found\")) throw error;\n      }\n    }\n    if (!p?.found) {\n      if (!name && !bid) throw new ExecError(`no running application with pid ${pid}; call list_apps for the current processes`);\n      const args = [];\n      if (urlArg) args.push(urlArg);\n      if (bid) args.unshift(\"-b\", bid); else args.unshift(\"-a\", name);\n      if (!activate) args.unshift(\"-g\");\n      const r = await runL(\"open\", args, { timeoutMs: 25_000 });\n      if (r.code !== 0) throw new ExecError(`open failed: ${r.stderr.trim().slice(0, 200)}`, r);\n      await new Promise((res) => setTimeout(res, 600));\n      p = await native(\"app_info\", { app_ref: find, activate });\n    }\n    if (activate && p?.frontmost === false) throw Object.assign(new ExecError(\"The selected application did not become frontmost; no input mode was enabled. Continue with background control or wait for the user.\"), { code: \"activation_not_confirmed\" });\n    if (p?.bundle_id === \"net.codewhale.computer-use\") throw Object.assign(new ExecError(\"The Computer Use setup and safety controls belong to the user and cannot be operated by this plugin.\"), { code: \"protected_application\" });\n    // A bare executable has no bundle id; carrying an empty one would make the\n    // identity unmatchable.\n    state.inputApp = { pid: p.pid, ...(p.bundle_id ? { bundle_id: p.bundle_id } : {}) };\n    state.foregroundInput = !!activate;\n    return { launched: true, activate, keyboard_delivery: activate ? \"foreground-guarded\" : \"process\", input_scope: activate ? \"shared-desktop\" : \"application\", shared_pointer: !!activate, isolated_desktop: false, url: urlArg ?? null, resolved: p?.found ? { name: p.name, pid: p.pid, bundle_id: p.bundle_id, frontmost: p.frontmost } : null };\n  }\n\n  // ---------- clipboard / cursor / waits ----------\n  async function readClipboard() {\n    const r = await runL(\"pbpaste\", [], { timeoutMs: 5_000, maxBuffer: 4 * 1024 * 1024 });\n    return { text: r.stdout, encoding: \"utf8\" };\n  }\n  async function writeClipboard({ text }) {","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/plugins/computer-use/src/backends/darwin.mjs#L552-L588","documentation":"The macOS `open` command (run with a 25s timeout to launch the app by -a name or -b bundle_id, optionally a URL and -g for background) exited non-zero. The first 200 characters of its stderr are embedded in the message and the full result is attached to the ExecError.","triggerScenarios":"open_application falls back to `open` when app_info found no matching running app; `open` fails because the app name is misspelled, the bundle id does not exist, the app is not installed, or the URL scheme is not handled.","commonSituations":"Typos in app names ('FireFox' vs 'Firefox'); referring to an app not installed on the machine; bundle id copied from a different platform; opening a URL whose scheme has no registered handler; Spotlight indexing issues making -a lookups fail.","solutions":["Read the embedded stderr (and the attached result object) for the precise `open` failure reason.","Verify the app exists: call list_apps, or check /Applications for the name/bundle id.","Use the exact bundle_id (via osascript or list_apps) instead of a display name when names are ambiguous.","If opening a URL, confirm a handler app is registered for its scheme."],"exampleFix":"// before\nawait backend.open_application({ name: \"FireFox\" });\n// after\nawait backend.open_application({ bundle_id: \"org.mozilla.firefox\" });","handlingStrategy":"try-catch","validationCode":"const apps = await backend.list_apps();\nif (!apps.some(a => a.name === appName || a.bundle_id === bundleId)) {\n  throw new Error(`app ${appName || bundleId} not installed/running`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await backend.open_application({ name });\n} catch (e) {\n  if (String(e.message).startsWith('open failed:')) {\n    console.error('`open` stderr:', e.message.slice('open failed:'.length));\n  } else throw e;\n}","preventionTips":["Use exact bundle_ids obtained from list_apps instead of display names.","Confirm the app is installed before calling open_application.","Check URL schemes have a registered handler before opening URLs."],"tags":["process-exit","macos","launch-failure","computer-use"],"backgroundTag":"command-not-found","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}