{"record":{"id":"ab974fa2fecd5893","repo":"jackwener/OpenCLI","slug":"model-wanted-not-found-in-trae-cn-model-menu","errorCode":null,"errorMessage":"Model \"${wanted}\" not found in Trae CN model menu","messagePattern":"Model \"(.+?)\" not found in Trae CN model menu","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":730,"sourceCode":"  const wantedKey = normalizeModelLabel(wanted);\n  let models = await page.evaluate(listOpenModelItemsScript());\n  if (!models || models.length === 0) {\n    await page.click(TRAE_CN_MODEL_TRIGGER_SELECTOR);\n    await page.wait(0.8);\n    models = await page.evaluate(listOpenModelItemsScript());\n  }\n  const exactMatch = models.find((item) => normalizeModelLabel(item.Model) === wantedKey);\n  const containsMatches = exactMatch\n    ? []\n    : models.filter((item) => normalizeModelLabel(item.Model).includes(wantedKey));\n  if (!exactMatch && containsMatches.length > 1) {\n    throw new ArgumentError(\n      `Model \"${wanted}\" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}`,\n    );\n  }\n  const match = exactMatch || containsMatches[0];\n  if (!match) {\n    throw new ArgumentError(`Model \"${wanted}\" not found in Trae CN model menu`);\n  }\n  await page.click(TRAE_CN_MODEL_ITEM_SELECTOR, { nth: match.Index });\n  await page.wait(0.8);\n  const info = await page.evaluate(inspectTraeShellScript());\n  const selectedLabel = info.model || '';\n  const selectedKey = normalizeModelLabel(selectedLabel);\n  const matchKey = normalizeModelLabel(match.Model);\n  if (!selectedKey || (selectedKey !== matchKey && selectedKey !== wantedKey)) {\n    throw new CommandExecutionError(\n      `Trae CN model switch did not verify the requested model: requested \"${wanted}\", current \"${selectedLabel || 'unknown'}\"`,\n      'Open the Trae CN model menu and verify the requested model is selectable, then retry.',\n    );\n  }\n  return {\n    requested: wanted,\n    selected: selectedLabel,\n    workspace: info.workspace || '',\n    agent: info.agent || '',","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L712-L748","documentation":"After exact and substring matching, if no model in the Trae CN menu matches the requested name, selectTraeModel throws this ArgumentError. The name normalization (lowercase, alphanumerics and dots only) still found nothing, so the model genuinely is not present in the menu.","triggerScenarios":"Requesting a model that does not exist in the installed Trae CN, a typo like 'gpt4o' vs 'gpt-4o' when normalization still misses, or the menu failed to load/populate before matching.","commonSituations":"Model names from docs of a different Trae edition (international vs CN), renamed models after a Trae update, or opening the menu too late.","solutions":["Use the exact model label shown in the Trae CN model menu","List available models first and pick a valid one","Ensure the model menu fully opens before selection (retry with a longer wait)","Check whether your Trae CN version offers that model at all"],"exampleFix":"// before\nselectTraeModel(page, 'claude-4-sonnet')\n// after\nselectTraeModel(page, 'claude-3-7-sonnet') // name present in current menu","handlingStrategy":"validation","validationCode":"const models = await page.evaluate(listModelsScript());\nif (!models.some(m => normalizeModelLabel(m.Model) === normalizeModelLabel(wanted)))\n  throw new Error(`Model \"${wanted}\" unavailable; available: ${models.map(m=>m.Model).join(', ')}`);","typeGuard":"const modelExists = (models, wanted) => models.some(m => normalizeModelLabel(m.Model) === normalizeModelLabel(wanted));","tryCatchPattern":"try { await selectTraeModel(page, name); } catch (e) { if (/not found in Trae CN model menu/.test(e.message)) { console.error('Pick one of the models listed in the Trae CN menu'); process.exitCode = 2; } else throw e; }","preventionTips":["Fetch and cache the available model list at startup","Keep a maintained map of valid model names for your Trae CN version","Open and let the model menu fully populate before matching"],"tags":["automation","argument-validation","model-not-found"],"backgroundTag":"model-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}