koala73/worldmonitor · error · ValidationError

Expected the essentials basket for the selected market

Error message

Expected the essentials basket for the selected market

What it means

A basket slug longer than 13 characters throws ValidationError('Expected the essentials basket for the selected market'). Only the essentials basket is served: the slug must be exactly `essentials-<market>` (max 2+10=12-13 chars).

Solutions

  1. Use the exact slug `essentials-<market>` (e.g. essentials-us) or omit basketSlug to get the default
  2. Shorten or remove the custom basket suffix from the request
  3. Do not append qualifiers like '-premium' to the basket slug
  4. If a richer basket is needed, request a new server-side basket instead of a longer slug

Example fix

// before
getConsumerPrices({ market: 'us', basket: 'essentials-us-extended' });
// after
getConsumerPrices({ market: 'us', basket: 'essentials-us' });
Defensive patterns

Strategy: validation

Validate before calling

if (basket && basket.length > 13) throw new Error('basket slug too long');

Type guard

const isShortBasketSlug = (b) => typeof b === 'string' && b.length <= 13;

Try / catch

try { return await getConsumerPrices(req); } catch (e) { if (e?.fieldViolations?.[0]?.field === 'basketSlug') { return getConsumerPrices({ ...req, basket: undefined }); } throw e; }

Prevention

When it happens

Trigger: Passing basketSlug like 'essentials-us-premium', 'full-basket-us', or any custom slug exceeding 13 characters to a consumer-prices endpoint.

Common situations: Clients guessing basket names; copied URLs from other product surfaces with richer baskets; attempting to request non-essentials baskets that this API does not support.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of koala73/worldmonitor@e586b8b4b8 (2026-09-22). Data as JSON: /api/errors/4a095d45950be6e3. Report an issue: GitHub.

Appendix: source

Thrown at server/worldmonitor/consumer-prices/v1/_selection.ts:14

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)