medusajs/medusa · error · MedusaError

invalid_data

invalid_data

Error message

Variants with IDs ${notFound.join(", ")} do not have a price

What it means

Store API route GET /store/gift-cards/[idOrCode] requires the path parameter to be non-empty. Because Express-style routing only matches when a segment exists, hitting this means the route was invoked with an empty code (e.g. rewritten/proxied request or direct handler invocation), yielding MedusaError INVALID_ARGUMENT.

Source

Thrown at packages/core/core-flows/src/cart/steps/get-variant-price-sets.ts:106

      }
    )
  ).data
}

/**
 * Validates that all variants without a custom price have price sets and throws error for missing ones
 */
function validateVariantPriceSets(
  variantPriceSets: VariantPriceSetData[],
  variantsWithCustomPrice: string[] = []
): void {
  const variantsWithCustomPriceSet = new Set(variantsWithCustomPrice)
  const notFound = variantPriceSets
    .filter((v) => !v.price_set?.id && !variantsWithCustomPriceSet.has(v.id))
    .map((v) => v.id)

  if (notFound.length) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Variants with IDs ${notFound.join(", ")} do not have a price`
    )
  }
}

/**
 * Unified function to process variants with context grouping optimization
 * TODO: to be discussed, support batch calculation from the pricing module. Currently
 * trying to mitigate the impact by grouping items by exact same context.
 */
async function processVariantPriceSets(
  pricingService: IPricingModuleService,
  items: PriceCalculationItem[],
  container: MedusaContainer
): Promise<GetVariantPriceSetsStepOutput> {
  const result: GetVariantPriceSetsStepOutput = {}

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Ensure the client always appends a real gift card code/id to the path
  2. Fix proxy/rewrite rules that drop the path segment
  3. Validate the code is non-empty client-side before making the request

Example fix

// before
fetch(`/store/gift-cards/${code}`) // code may be ''
// after
if (!code) throw new Error('gift card code required')
fetch(`/store/gift-cards/${encodeURIComponent(code)}`)
Defensive patterns

Strategy: validation

Validate before calling

if (!code) throw new Error('gift card code is required')
await sdk.store.giftCard.retrieve(code)

Type guard

const isNonEmptyCode = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0

Try / catch

catch (e) { if (e.type === 'invalid_argument') return res.status(400).json({ message: 'code required' }); throw e }

Prevention

When it happens

Trigger: Requests like GET /store/gift-cards/ (trailing slash, empty segment) or internal calls to the handler with idOrCode unset; also custom middleware rewriting URLs to an empty param.

Common situations: Misconfigured rewrites/proxies stripping the code segment; client code building the URL with an undefined variable producing '/gift-cards/'.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/0683e4a20e8688bd. Report an issue: GitHub.