{"record":{"id":"25e6c3e5450299bc","repo":"Hmbown/CodeWhale","slug":"start-process-failed-r-stderr-trim-slice-0-200","errorCode":null,"errorMessage":"Start-Process failed: ${r.stderr.trim().slice(0, 200)}","messagePattern":"Start-Process failed: (.+?)","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/win32.mjs","lineNumber":354,"sourceCode":"    },\n    open_application: async ({ name, bundle_id: bid, url: urlArg, activate } = {}) => {\n      const target = name ?? bid;\n      if (typeof target !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9 .:_-]*$/.test(target)) throw new ExecError(\"open_application needs a plain app or executable name\");\n      let argumentsScript = \"\";\n      if (urlArg != null) {\n        if (typeof urlArg !== \"string\" || !URL.canParse(urlArg) || /[\\0\\r\\n]/.test(urlArg)) throw new ExecError(\"open_application url must be an absolute URL\");\n        // Start-Process joins ArgumentList into a Windows command line. Quote\n        // one argument there, and transport that string as data into PowerShell.\n        const quoted = '\"' + urlArg.replace(/(\\\\*)\"/g, '$1$1\\\\\"').replace(/(\\\\+)$/g, '$1$1') + '\"';\n        const encoded = Buffer.from(quoted, \"utf16le\").toString(\"base64\");\n        argumentsScript = `$launchArg = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${encoded}')); `;\n      }\n      // activate defaults to background on every platform: a minimized\n      // launch leaves the user's foreground window alone. Windows input is\n      // still shared-surface — this only controls the launch, not input.\n      const windowStyle = activate === true ? \"\" : \" -WindowStyle Minimized\";\n      const r = await psOk(`${argumentsScript}Start-Process -FilePath \"${target}\"${windowStyle}${urlArg != null ? \" -ArgumentList $launchArg\" : \"\"}; Write-Output '{\"launched\": true}'`, { timeoutMs: 20_000 });\n      if (r.code !== 0) throw new ExecError(`Start-Process failed: ${r.stderr.trim().slice(0, 200)}`, r);\n      return { launched: true, name: target, url: urlArg ?? null, activate: activate === true };\n    },\n    get_app_state: async (args = {}) => {\n      if (Object.hasOwn(args, \"window_id\")) throw unsupportedSelector(\"Windows get_app_state does not support window_id\");\n      const { app_ref, detail } = args;\n      if (Object.hasOwn(args, \"app_ref\") && (!app_ref || typeof app_ref !== \"object\" || Array.isArray(app_ref)\n        || Object.keys(app_ref).length !== 1 || !Object.hasOwn(app_ref, \"name\") || typeof app_ref.name !== \"string\" || !app_ref.name.trim())) {\n        throw unsupportedSelector(\"Windows get_app_state supports only app_ref: { name: exact window title }; PID, bundle_id and other references are unsupported\");\n      }\n      const filter = Buffer.from(app_ref?.name ?? \"\", \"utf16le\").toString(\"base64\");\n      const maxEls = detail === \"full\" ? 800 : 400;\n      const j = await psJson(`${UIA_PRELUDE}\n$max = ${maxEls};\n$filter = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${filter}'));\n$root = [System.Windows.Automation.AutomationElement]::RootElement;\n$els = New-Object System.Collections.ArrayList;\n$found = $false; $truncated = $false; $appName = $null;\n$targets = @($root.FindAll([System.Windows.Automation.TreeScope]::Children, [System.Windows.Automation.Condition]::TrueCondition));","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/win32.mjs#L336-L372","documentation":"open_application runs PowerShell's Start-Process to launch the target and throws this ExecError (carrying the process result r) when PowerShell exits non-zero. The message includes up to 200 characters of PowerShell stderr, which names the real cause.","triggerScenarios":"Launching a name that isn't an installed app or on PATH (Start-Process cannot find the file); launching a .exe path with spaces mishandled; missing app association for a URL scheme; PowerShell/profile or execution-policy problems.","commonSituations":"Typos in the executable name; app not installed on the target Windows machine; attempting to open a URL whose protocol handler is unregistered; running in restricted environments where Start-Process is blocked.","solutions":["Read the embedded stderr slice in the message — it names the missing file or handler","Verify the app is installed and resolvable by bare name (try the full app name as registered, e.g. \"Mozilla Firefox\")","For URLs, confirm a default handler exists for the scheme (e.g. https opens in some browser)","Catch the ExecError, inspect err's attached process result, and fall back to list_apps to discover valid app names"],"exampleFix":"// before\nawait openApplication({ name: \"ffox\" });\n// after\nawait openApplication({ name: \"firefox\" }); // or verify via list_apps first","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await backend.open_application({ name });\n} catch (e) {\n  if (String(e.message).startsWith(\"Start-Process failed\")) {\n    // e carries the process result; log stderr slice from the message\n    const apps = await backend.list_apps();\n    throw new Error(`Could not launch \"${name}\". Installed candidates: ${apps.displays ?? JSON.stringify(apps).slice(0, 300)}`);\n  }\n  throw e;\n}","preventionTips":["Read the stderr slice embedded in the message for the root cause","Verify the app is installed and resolvable by its registered name","Confirm URL schemes have default handlers before launching","Retain the ExecError's attached process result for diagnostics"],"tags":["process","windows","powershell"],"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"}