Hmbown/CodeWhale · error · ExecError

set_value failed

Error message

set_value failed

What it means

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.

Solutions

  1. Re-check the element is not read-only before calling set_value (inspect it with UIA tooling like inspect.exe or Accessibility Insights).
  2. Fall back to keyboard input: click the element then send keystrokes via the backend's type action instead of the a11y set_value path.
  3. Verify the selector (automation id / name / role) still matches the current app state — re-resolve after UI updates.
  4. If the app is unresponsive, wait or restart it; a hung UIA provider trips the 45s timeout.

Example fix

// before
await backend.set_value({ target, value });
// after
try {
  await backend.set_value({ target, value });
} catch (e) {
  if (String(e.message).includes('element_read_only') || true) {
    await backend.click({ target });
    await backend.type({ text: value }); // keyboard fallback
  }
}
Defensive patterns

Strategy: fallback

Type guard

const isSetValueError = (e) => e instanceof Error && e.message === 'set_value failed';

Try / catch

try {
  return await backend.set_value({ target, value });
} catch (e) {
  if (isSetValueError(e)) {
    await backend.click({ target });
    await backend.type({ text: value }); // keyboard fallback
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/62a8863be3e84387. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/plugins/computer-use/src/backends/win32.mjs:544

      const event = (code, flags) => `[User32]::SendKey(${code}, ${flags});`;
      return withKeys(keys, async () => {
        await withUser32(`${keys.map((code) => event(code, 0)).join("\n")}
Start-Sleep -Milliseconds ${Math.round(d * 1000)};
${[...keys].reverse().map((code) => event(code, 2)).join("\n")}
Write-Output '{"ok": true}';`, { timeoutMs: Math.max(10_000, d * 1000 + 8000) });
        return { action_sent: true, key, heldSec: d };
      });
    },
    set_value: async ({ target, value }) => {
      const resolve = elementScript(target);
      const b64 = Buffer.from(String(value ?? ""), "utf16le").toString("base64");
      const j = await psJson(`${resolve}
$val = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${b64}'));
$vp = $cur.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern);
if ($vp.Current.IsReadOnly) { throw 'element_read_only' }
$vp.SetValue($val);
@{ ok = $true; verified = ($vp.Current.Value -ceq $val) } | ConvertTo-Json -Compress;`, { timeoutMs: 45_000 });
      if (!j.ok) throw new ExecError("set_value failed");
      return { action_sent: true, strategy: "a11y", verified: j.verified === true };
    },
    select_text: async () => { throw new ExecError("select_text is not implemented on the win32 backend yet — fail-closed"); },
    perform_action: async ({ target, action = "Invoke" }) => {
      const resolve = elementScript(target);
      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"] };
      const chosen = actions[String(action).toLowerCase()];
      if (!chosen) throw new ExecError("unsupported UIA action");
      await psOk(`${resolve}
$pattern = $cur.GetCurrentPattern([System.Windows.Automation.${chosen[0]}Pattern]::Pattern);
$pattern.${chosen[1]}();`, { timeoutMs: 45_000 });
      return { action_sent: true, strategy: "a11y", action };
    },
    read_clipboard: async () => {
      const j = await psJson(`$t = Get-Clipboard -Raw -ErrorAction SilentlyContinue;
@{ text = [string]$t } | ConvertTo-Json -Compress;`, { timeoutMs: 10_000 });
      return { text: j.text ?? "", encoding: "utf8" };
    },

View on GitHub (pinned to 73e0f67d83)