500 TypeError (reading 'calculated_amount') instead of 400 "do not have a price" when adding a variant unpriced in the cart's region#15932
Package.json file
Hit in production on @medusajs/medusa 2.15.5; the buggy code is unchanged on current develop (2962faf65701) and in v2.17.2.
Node.js version
v22 (any)
Database and its version
PostgreSQL 16
Operating system name and version
Linux (Kubernetes), reproduces anywhere
Browser name
N/A (Store API)
What happened?
POST /store/carts/{id}/line-items returns a raw 500 (TypeError: Cannot read properties of undefined (reading 'calculated_amount')) instead of the intended 400 "Variants with IDs … do not have a price" when the variant exists and is published but has no calculated price for the cart's region/currency.
Root cause
In packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts (permalink lines below are on develop @ 2962faf65701; the same logic ships compiled in @medusajs/core-flows dist/cart/workflows/get-variants-and-items-with-prices.js):
- The missing price is correctly detected and collected — but not thrown yet: