jackwener/OpenCLI · error · ArgumentError
target must be "code" or "work"
Error message
target must be "code" or "work"
What it means
The mode command's target argument accepts only 'code' or 'work' (case/whitespace-insensitive). Any other non-empty value — while omitted/empty values are allowed and mean 'read current mode' — is rejected with this ArgumentError before touching the UI.
Source
Thrown at clis/trae-solo/mode.js:24
// aria-label is "Switch to Work mode" when on Code, and "Switch to Code
// mode" when on Work. Clicking it toggles between the two.
cli({
site: 'trae-solo',
name: 'mode',
access: 'write',
description: 'Read or switch TRAE SOLO between Code mode and Work mode.',
domain: 'localhost',
strategy: Strategy.UI,
browser: true,
args: [
{ name: 'target', positional: true, required: false, help: 'Target mode: code or work. Omit to read current.' },
],
columns: ['Status', 'Mode'],
func: async (page, kwargs) => {
const want = String(kwargs.target || '').trim().toLowerCase();
if (want && !['code', 'work'].includes(want)) {
throw new ArgumentError('target must be "code" or "work"');
}
const current = await page.evaluate(`(function() {
const cap = document.querySelector('[class*="capsule"]');
if (!cap) return '';
const aria = cap.getAttribute('aria-label') || '';
// aria says "Switch to <Other> mode" — current is the OTHER one.
const m = aria.match(/Switch to (Code|Work) mode/i);
if (m) return m[1].toLowerCase() === 'work' ? 'code' : 'work';
return '';
})()`);
if (!current) {
throw selectorError('TRAE SOLO mode capsule (.index-module__capsule__ ...).');
}
if (!want) {
return [{ Status: 'Active', Mode: current }];
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass exactly 'code' or 'work' (case-insensitive)
- Omit the target argument entirely to just read the current mode
- Check the command's help text for the accepted values
Example fix
// before
await traeSoloCli.mode({ target: 'build' }); // throws
// after
await traeSoloCli.mode({ target: 'work' }); Defensive patterns
Strategy: validation
Validate before calling
const t = String(target ?? '').trim().toLowerCase();
if (t && !['code', 'work'].includes(t)) throw new Error('target must be "code" or "work"'); Type guard
const isModeTarget = (t) => ['code','work'].includes(String(t ?? '').trim().toLowerCase());
Try / catch
try {
await traeSoloCli.mode({ target });
} catch (e) {
if (e instanceof ArgumentError && /"code" or "work"/.test(e.message)) {
console.error('Usage: mode [code|work] — omit to read current.');
} else throw e;
} Prevention
- Only pass the bare keywords 'code' or 'work'
- Omit target to read the current mode instead of guessing values
- Add CLI parsing validation before invoking the command
When it happens
Trigger: Passing target values like 'writer', 'build', 'Code Mode', 'coding', or any string not in ['code','work'] after trim+lowercase.
Common situations: Confusing Trae SOLO's Code/Work mode toggle with other IDE modes; guessing synonyms; copy-pasting a longer UI label like 'Work Mode' instead of the bare keyword.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- tab must be configured / run-history / task-template
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/555d8c15b4410b73.
Report an issue: GitHub.