{"record":{"id":"555d8c15b4410b73","repo":"jackwener/OpenCLI","slug":"target-must-be-code-or-work","errorCode":null,"errorMessage":"target must be \"code\" or \"work\"","messagePattern":"target must be \"code\" or \"work\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-solo/mode.js","lineNumber":24,"sourceCode":"// aria-label is \"Switch to Work mode\" when on Code, and \"Switch to Code\n// mode\" when on Work. Clicking it toggles between the two.\n\ncli({\n    site: 'trae-solo',\n    name: 'mode',\n    access: 'write',\n    description: 'Read or switch TRAE SOLO between Code mode and Work mode.',\n    domain: 'localhost',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'target', positional: true, required: false, help: 'Target mode: code or work. Omit to read current.' },\n    ],\n    columns: ['Status', 'Mode'],\n    func: async (page, kwargs) => {\n        const want = String(kwargs.target || '').trim().toLowerCase();\n        if (want && !['code', 'work'].includes(want)) {\n            throw new ArgumentError('target must be \"code\" or \"work\"');\n        }\n\n        const current = await page.evaluate(`(function() {\n      const cap = document.querySelector('[class*=\"capsule\"]');\n      if (!cap) return '';\n      const aria = cap.getAttribute('aria-label') || '';\n      // aria says \"Switch to <Other> mode\" — current is the OTHER one.\n      const m = aria.match(/Switch to (Code|Work) mode/i);\n      if (m) return m[1].toLowerCase() === 'work' ? 'code' : 'work';\n      return '';\n    })()`);\n        if (!current) {\n            throw selectorError('TRAE SOLO mode capsule (.index-module__capsule__ ...).');\n        }\n\n        if (!want) {\n            return [{ Status: 'Active', Mode: current }];\n        }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-solo/mode.js#L6-L42","documentation":"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.","triggerScenarios":"Passing target values like 'writer', 'build', 'Code Mode', 'coding', or any string not in ['code','work'] after trim+lowercase.","commonSituations":"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.","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"],"exampleFix":"// before\nawait traeSoloCli.mode({ target: 'build' }); // throws\n// after\nawait traeSoloCli.mode({ target: 'work' });","handlingStrategy":"validation","validationCode":"const t = String(target ?? '').trim().toLowerCase();\nif (t && !['code', 'work'].includes(t)) throw new Error('target must be \"code\" or \"work\"');","typeGuard":"const isModeTarget = (t) => ['code','work'].includes(String(t ?? '').trim().toLowerCase());","tryCatchPattern":"try {\n  await traeSoloCli.mode({ target });\n} catch (e) {\n  if (e instanceof ArgumentError && /\"code\" or \"work\"/.test(e.message)) {\n    console.error('Usage: mode [code|work] — omit to read current.');\n  } else throw e;\n}","preventionTips":["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"],"tags":["argument-validation","cli","trae-solo"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}