koala73/worldmonitor · error · ValidationError
Expected a supported two-letter market code
Error message
Expected a supported two-letter market code
What it means
resolveConsumerPriceSelection validates the market code: if it is longer than 2 characters it throws ValidationError('Expected a supported two-letter market code'). Markets must be a two-letter code from the supported set (ae, sa, ch, sg, us, gb, br, in, au, ke), defaulting to 'ae'.
Solutions
- Send a two-letter market code from the supported list (ae, sa, ch, sg, us, gb, br, in, au, ke)
- Convert ISO alpha-3 codes to alpha-2 client-side before the call
- Truncate/validate the market input to max length 2 before calling
- Omit the market parameter to use the 'ae' default
Example fix
// before
getConsumerPrices({ market: 'USA' });
// after
const alpha2 = { USA: 'us', GBR: 'gb' }[code] ?? code.slice(0, 2).toLowerCase();
getConsumerPrices({ market: alpha2 }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof market !== 'string' || market.length > 2) throw new Error('market must be <=2 chars'); Type guard
const isShortMarketCode = (m) => typeof m === 'string' && m.length <= 2;
Try / catch
try { return await getConsumerPrices({ market }); } catch (e) { if (e?.fieldViolations?.[0]?.field === 'marketCode') { return getConsumerPrices({ market: normalizeMarket(market) }); } throw e; } Prevention
- Always convert ISO alpha-3 / locale codes to alpha-2 before calls
- Keep a shared client constant mirroring the server market list
- Validate market input at the form/URL parsing layer
- Never concatenate market with other qualifiers
When it happens
Trigger: Calling a consumer-prices endpoint with marketCode of length >2, e.g. market=USA, market=are, or a full country name passed in the query/path.
Common situations: Passing a three-letter ISO-3166 alpha-3 code (USA, GBR) instead of alpha-2; passing locale strings like 'en-US'; concatenated market+basket values.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Expected the essentials basket for the selected market
- disruptionPct must be an integer from 0 to 100 for a…
- EONET malformed event
- Expected an array of Sentry issues. A Sentry error body is…
- Expected at most 20 IATA airport codes
AI-assisted analysis of koala73/worldmonitor@e586b8b4b8 (2026-09-22).
Data as JSON: /api/errors/bf0bac994a1d8ea6.
Report an issue: GitHub.
Appendix: source
Thrown at server/worldmonitor/consumer-prices/v1/_selection.ts:7
import { ValidationError } from '../../../../src/generated/server/worldmonitor/consumer_prices/v1/service_server';
const MARKETS = new Set(['ae', 'sa', 'ch', 'sg', 'us', 'gb', 'br', 'in', 'au', 'ke']);
export function resolveConsumerPriceSelection(marketCode = '', basketSlug = ''): { market: string; basket: string } {
if (marketCode.length > 2) {
throw new ValidationError([{ field: 'marketCode', description: 'Expected a supported two-letter market code' }]);
}
const market = marketCode.toLowerCase() || 'ae';
if (!MARKETS.has(market)) {
throw new ValidationError([{ field: 'marketCode', description: 'Expected a supported two-letter market code' }]);
}
if (basketSlug.length > 13) {
throw new ValidationError([{ field: 'basketSlug', description: 'Expected the essentials basket for the selected market' }]);
}
const basket = basketSlug.toLowerCase() || `essentials-${market}`;
if (basket !== `essentials-${market}`) {
throw new ValidationError([{ field: 'basketSlug', description: 'Expected the essentials basket for the selected market' }]);
}
return { market, basket };
}
View on GitHub (pinned to e586b8b4b8)