jackwener/OpenCLI · error · ArgumentError

Model "${wanted}" not found in Trae CN model menu

Error message

Model "${wanted}" not found in Trae CN model menu

What it means

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.

Source

Thrown at clis/trae-cn/utils.js:730

  const wantedKey = normalizeModelLabel(wanted);
  let models = await page.evaluate(listOpenModelItemsScript());
  if (!models || models.length === 0) {
    await page.click(TRAE_CN_MODEL_TRIGGER_SELECTOR);
    await page.wait(0.8);
    models = await page.evaluate(listOpenModelItemsScript());
  }
  const exactMatch = models.find((item) => normalizeModelLabel(item.Model) === wantedKey);
  const containsMatches = exactMatch
    ? []
    : models.filter((item) => normalizeModelLabel(item.Model).includes(wantedKey));
  if (!exactMatch && containsMatches.length > 1) {
    throw new ArgumentError(
      `Model "${wanted}" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}`,
    );
  }
  const match = exactMatch || containsMatches[0];
  if (!match) {
    throw new ArgumentError(`Model "${wanted}" not found in Trae CN model menu`);
  }
  await page.click(TRAE_CN_MODEL_ITEM_SELECTOR, { nth: match.Index });
  await page.wait(0.8);
  const info = await page.evaluate(inspectTraeShellScript());
  const selectedLabel = info.model || '';
  const selectedKey = normalizeModelLabel(selectedLabel);
  const matchKey = normalizeModelLabel(match.Model);
  if (!selectedKey || (selectedKey !== matchKey && selectedKey !== wantedKey)) {
    throw new CommandExecutionError(
      `Trae CN model switch did not verify the requested model: requested "${wanted}", current "${selectedLabel || 'unknown'}"`,
      'Open the Trae CN model menu and verify the requested model is selectable, then retry.',
    );
  }
  return {
    requested: wanted,
    selected: selectedLabel,
    workspace: info.workspace || '',
    agent: info.agent || '',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the exact model label shown in the Trae CN model menu
  2. List available models first and pick a valid one
  3. Ensure the model menu fully opens before selection (retry with a longer wait)
  4. Check whether your Trae CN version offers that model at all

Example fix

// before
selectTraeModel(page, 'claude-4-sonnet')
// after
selectTraeModel(page, 'claude-3-7-sonnet') // name present in current menu
Defensive patterns

Strategy: validation

Validate before calling

const models = await page.evaluate(listModelsScript());
if (!models.some(m => normalizeModelLabel(m.Model) === normalizeModelLabel(wanted)))
  throw new Error(`Model "${wanted}" unavailable; available: ${models.map(m=>m.Model).join(', ')}`);

Type guard

const modelExists = (models, wanted) => models.some(m => normalizeModelLabel(m.Model) === normalizeModelLabel(wanted));

Try / catch

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; }

Prevention

When it happens

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

Common situations: Model names from docs of a different Trae edition (international vs CN), renamed models after a Trae update, or opening the menu too late.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ab974fa2fecd5893. Report an issue: GitHub.