koala73/worldmonitor · error · Error

Unknown scorecard bloc preset: ${preset}

Error message

Unknown scorecard bloc preset: ${preset}

What it means

resolveBlocSelection validates the preset name against the SCORECARD_BLOC_PRESETS record (USMCA, EU27, ASEAN, BRICS, etc.) and throws this error for any preset string not present as a key. Preset names are case-sensitive and exact; typo'd, lowercased, or deprecated preset ids are rejected so callers always get an official, curated member list.

Source

Thrown at server/worldmonitor/scorecard/v1/_bloc-presets.ts:33

  },
  BRICS: { id: 'BRICS', label: 'BRICS', members: ['BR', 'RU', 'IN', 'CN', 'ZA', 'SA', 'EG', 'AE', 'ET', 'ID', 'IR'] },
  GCC: { id: 'GCC', label: 'Gulf Cooperation Council', members: ['AE', 'BH', 'KW', 'OM', 'QA', 'SA'] },
  ASEAN: { id: 'ASEAN', label: 'ASEAN', members: ['BN', 'KH', 'ID', 'LA', 'MY', 'MM', 'PH', 'SG', 'TH', 'TL', 'VN'] },
  NATO: {
    id: 'NATO',
    label: 'NATO',
    members: ['AL', 'BE', 'BG', 'CA', 'HR', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IS', 'IT', 'LV', 'LT', 'LU', 'ME', 'NL', 'MK', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'TR', 'GB', 'US'],
  },
};

export function resolveBlocSelection(input: { preset?: string; members?: string[] }): ScorecardBlocSelection {
  const preset = String(input.preset || '').trim();
  const members = Array.isArray(input.members) ? input.members : [];
  if (Boolean(preset) === (members.length > 0)) {
    throw new Error('Select exactly one scorecard bloc preset or custom member list.');
  }
  if (preset) {
    if (!(preset in SCORECARD_BLOC_PRESETS)) throw new Error(`Unknown scorecard bloc preset: ${preset}`);
    return SCORECARD_BLOC_PRESETS[preset as ScorecardBlocPreset];
  }
  if (members.length < 2 || members.length > 30) throw new Error('Custom scorecard blocs require 2-30 members.');
  if (members.some((member) => !/^[A-Z]{2}$/.test(member))) {
    throw new Error('Custom scorecard bloc members must be uppercase ISO-2 codes.');
  }
  if (new Set(members).size !== members.length) throw new Error('Custom scorecard bloc members must be unique.');
  if (members.some((member) => !isInRankableUniverse(member))) {
    throw new Error('Custom scorecard bloc members must belong to the public rankable country universe.');
  }
  const sorted = [...members].sort();
  return { id: `custom:${sorted.join('-')}`, label: sorted.join(' + '), members: sorted };
}

View on GitHub (pinned to 9361220cc0)

Solutions

  1. Use an exact preset id from SCORECARD_BLOC_PRESETS (e.g., 'USMCA', 'EU27'), case-sensitive.
  2. Discover valid ids at runtime from the API's preset listing instead of hardcoding strings.
  3. For user-typed input, normalize and map to the closest valid id before sending, or switch to a custom members list instead.
  4. If a preset was renamed or removed, migrate to the new id (e.g., NAFTA → USMCA).

Example fix

// before
resolveBlocSelection({ preset: 'eu27' }); // throws: not a key
// after
const id = presetName.trim().toUpperCase() === 'EU' ? 'EU27' : presetName;
if (!(id in SCORECARD_BLOC_PRESETS)) throw new Error(`Unknown preset ${id}`);
resolveBlocSelection({ preset: id });
Defensive patterns

Strategy: validation

Validate before calling

const VALID_PRESETS = ['USMCA','EU27','ASEAN','BRICS']; // fetch dynamically when possible
if (!VALID_PRESETS.includes(preset)) throw new Error(`Unknown preset: ${preset}`);

Type guard

function isBlocPreset(p: string): p is keyof typeof SCORECARD_BLOC_PRESETS {
  return p in SCORECARD_BLOC_PRESETS;
}

Try / catch

try {
  const bloc = await getBlocScorecard({ preset });
} catch (err) {
  if (err.message.startsWith('Unknown scorecard bloc preset')) {
    return badRequest(`preset must be one of: ${Object.keys(SCORECARD_BLOC_PRESETS).join(', ')}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getBlocScorecardWithReader with preset set to a string not in SCORECARD_BLOC_PRESETS: 'eu27' (lowercase), 'E.U.', 'EU' (not the exact 'EU27'), 'NAFTA' (renamed to USMCA), an empty-after-trim string when members is also empty (that hits the XOR error first), or a preset id removed in a newer API version.

Common situations: 1) Client hardcodes an outdated preset name after a rename (NAFTA→USMCA); 2) case mismatch from user-typed input; 3) version drift where server added/removed presets and the client uses an old list; 4) localization code translating preset labels back into the request field instead of sending the id.

Related errors


AI-assisted analysis of koala73/worldmonitor@9361220cc0 (2026-09-01). Data as JSON: /api/errors/ba6defc37e3779a7. Report an issue: GitHub.