{"record":{"id":"e62e6356fd0008d9","repo":"medusajs/medusa","slug":"currency-code-needs-to-be-a-string","errorCode":null,"errorMessage":"Currency code needs to be a string","messagePattern":"Currency code needs to be a string","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/core/utils/src/common/normalize-currency-code.ts","lineNumber":9,"sourceCode":"import { MedusaError, MedusaErrorTypes } from \"./errors\"\nimport { isString } from \"./is-string\"\n\n/**\n * Normalizes `currencyCode` by transforming it to lowercase\n */\nexport function normalizeCurrencyCode(currencyCode: string) {\n    if (!isString(currencyCode)) {\n        throw new MedusaError(MedusaErrorTypes.INVALID_ARGUMENT, \"Currency code needs to be a string\")\n    }\n\n    return currencyCode.toLowerCase()\n}","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/utils/src/common/normalize-currency-code.ts#L1-L13","documentation":"normalizeCurrencyCode requires its argument to be a string and throws INVALID_ARGUMENT otherwise. It is applied throughout carts, orders, product imports, and filters to lowercase currency codes.","triggerScenarios":"Passing undefined/null/number as currencyCode, e.g. adding a cart line without currency_code, or importing variants whose currency column is empty.","commonSituations":"Optional currency fields flowing from CSV import rows, third-party price feeds sending numbers (\"100\" vs 100), or requests missing the region/currency context.","solutions":["Default or require currency_code upstream (derive from region/cart before calling)","Coerce/validate with zod or a manual string check before calling the API/workflow","Fix the data source to always provide an uppercase/lowercase 3-letter string"],"exampleFix":"// before\nawait cartService.addLineItem(cartId, { variant_id, quantity }) // missing currency\n// after\nconst currency = z.string().length(3).parse(cart.currency_code)\nawait lineItemOps({ ...item, currency_code: currency })","handlingStrategy":"type-guard","validationCode":"const cur = input.currency_code ?? cart?.currency_code ?? region?.currency_code\nif (typeof cur !== 'string' || cur.length !== 3) throw new Error('currency_code required')","typeGuard":"const isCurrencyCode = (v: unknown): v is string => typeof v === 'string' && /^[a-zA-Z]{3}$/.test(v)","tryCatchPattern":null,"preventionTips":["Derive currency from cart/region before price mutations","Validate import rows for a 3-letter currency column"],"tags":["currency","validation","input","carts"],"backgroundTag":"invalid-currency-code","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}