{"record":{"id":"62a8863be3e84387","repo":"Hmbown/CodeWhale","slug":"set-value-failed","errorCode":null,"errorMessage":"set_value failed","messagePattern":"set_value failed","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/win32.mjs","lineNumber":544,"sourceCode":"      const event = (code, flags) => `[User32]::SendKey(${code}, ${flags});`;\n      return withKeys(keys, async () => {\n        await withUser32(`${keys.map((code) => event(code, 0)).join(\"\\n\")}\nStart-Sleep -Milliseconds ${Math.round(d * 1000)};\n${[...keys].reverse().map((code) => event(code, 2)).join(\"\\n\")}\nWrite-Output '{\"ok\": true}';`, { timeoutMs: Math.max(10_000, d * 1000 + 8000) });\n        return { action_sent: true, key, heldSec: d };\n      });\n    },\n    set_value: async ({ target, value }) => {\n      const resolve = elementScript(target);\n      const b64 = Buffer.from(String(value ?? \"\"), \"utf16le\").toString(\"base64\");\n      const j = await psJson(`${resolve}\n$val = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${b64}'));\n$vp = $cur.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern);\nif ($vp.Current.IsReadOnly) { throw 'element_read_only' }\n$vp.SetValue($val);\n@{ ok = $true; verified = ($vp.Current.Value -ceq $val) } | ConvertTo-Json -Compress;`, { timeoutMs: 45_000 });\n      if (!j.ok) throw new ExecError(\"set_value failed\");\n      return { action_sent: true, strategy: \"a11y\", verified: j.verified === true };\n    },\n    select_text: async () => { throw new ExecError(\"select_text is not implemented on the win32 backend yet — fail-closed\"); },\n    perform_action: async ({ target, action = \"Invoke\" }) => {\n      const resolve = elementScript(target);\n      const actions = { invoke: [\"Invoke\", \"Invoke\"], click: [\"Invoke\", \"Invoke\"], toggle: [\"Toggle\", \"Toggle\"], expand: [\"ExpandCollapse\", \"Expand\"], expandcollapse: [\"ExpandCollapse\", \"Expand\"], collapse: [\"ExpandCollapse\", \"Collapse\"], select: [\"SelectionItem\", \"Select\"], selectionitem: [\"SelectionItem\", \"Select\"] };\n      const chosen = actions[String(action).toLowerCase()];\n      if (!chosen) throw new ExecError(\"unsupported UIA action\");\n      await psOk(`${resolve}\n$pattern = $cur.GetCurrentPattern([System.Windows.Automation.${chosen[0]}Pattern]::Pattern);\n$pattern.${chosen[1]}();`, { timeoutMs: 45_000 });\n      return { action_sent: true, strategy: \"a11y\", action };\n    },\n    read_clipboard: async () => {\n      const j = await psJson(`$t = Get-Clipboard -Raw -ErrorAction SilentlyContinue;\n@{ text = [string]$t } | ConvertTo-Json -Compress;`, { timeoutMs: 10_000 });\n      return { text: j.text ?? \"\", encoding: \"utf8\" };\n    },","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/win32.mjs#L526-L562","documentation":"set_value on the win32 backend resolves a UI Automation element and calls ValuePattern.SetValue via PowerShell, returning JSON. When the script reports ok=false (script threw, e.g. 'element_read_only', or element could not be resolved/pattern unsupported), the backend throws this terse ExecError. The underlying PowerShell stderr is not embedded, so diagnosing requires re-running the action or checking the target element.","triggerScenarios":"Calling set_value where: the target element resolves to nothing, the element's IsReadOnly is true (script throws 'element_read_only'), the control does not implement ValuePattern, SetValue is rejected by the app, or the 45s PowerShell timeout is hit and psJson returns a failure result.","commonSituations":"Trying to type into a read-only combobox or password field that exposes no value pattern; targeting a custom-drawn control with no UIA value support; app UIA provider hangs so the 45s timeout fires; stale automation id after the app rebuilt its UI.","solutions":["Re-check the element is not read-only before calling set_value (inspect it with UIA tooling like inspect.exe or Accessibility Insights).","Fall back to keyboard input: click the element then send keystrokes via the backend's type action instead of the a11y set_value path.","Verify the selector (automation id / name / role) still matches the current app state — re-resolve after UI updates.","If the app is unresponsive, wait or restart it; a hung UIA provider trips the 45s timeout."],"exampleFix":"// before\nawait backend.set_value({ target, value });\n// after\ntry {\n  await backend.set_value({ target, value });\n} catch (e) {\n  if (String(e.message).includes('element_read_only') || true) {\n    await backend.click({ target });\n    await backend.type({ text: value }); // keyboard fallback\n  }\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"const isSetValueError = (e) => e instanceof Error && e.message === 'set_value failed';","tryCatchPattern":"try {\n  return await backend.set_value({ target, value });\n} catch (e) {\n  if (isSetValueError(e)) {\n    await backend.click({ target });\n    await backend.type({ text: value }); // keyboard fallback\n    return;\n  }\n  throw e;\n}","preventionTips":["Check element read-only state with UIA tooling before calling set_value.","Prefer keyboard-based input for fields known to lack a working ValuePattern.","Re-resolve selectors after the target app rebuilds its UI.","Watch for 45s-timeout hangs indicating a blocked UIA provider."],"tags":["windows","uia","accessibility","automation"],"backgroundTag":"unsupported-operation","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"}