{"record":{"id":"e00cd503259138fb","repo":"medusajs/medusa","slug":"the-following-rules-does-not-exists-array-from","errorCode":null,"errorMessage":"The following rules does not exists: ${Array.from(nonAlreadyExistingRules).join(\", \")} on shipping option ${shippingOptionUpdateData.id}","messagePattern":"The following rules does not exists: (.+?) on shipping option (.+?)","errorType":"exception","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/modules/fulfillment/src/services/fulfillment-module-service.ts","lineNumber":2137,"sourceCode":"    shippingOptionUpdateData: FulfillmentTypes.UpdateShippingOptionDTO\n  ) {\n    if (!shippingOptionUpdateData.rules) {\n      return\n    }\n\n    const existingRules = shippingOption.rules\n\n    const rulesSet = new Set(existingRules.map((r) => r.id))\n    // Only validate the rules that have an id to validate that they really exists in the shipping option\n    const expectedRuleSet = new Set(\n      shippingOptionUpdateData.rules\n        .map((r) => \"id\" in r && r.id)\n        .filter((id): id is string => !!id)\n    )\n    const nonAlreadyExistingRules = getSetDifference(expectedRuleSet, rulesSet)\n\n    if (nonAlreadyExistingRules.size) {\n      throw new MedusaError(\n        MedusaError.Types.NOT_FOUND,\n        `The following rules does not exists: ${Array.from(\n          nonAlreadyExistingRules\n        ).join(\", \")} on shipping option ${shippingOptionUpdateData.id}`\n      )\n    }\n  }\n\n  protected static validateGeoZones(\n    geoZones: (\n      | (Partial<FulfillmentTypes.CreateGeoZoneDTO> & { type: string })\n      | (Partial<FulfillmentTypes.UpdateGeoZoneDTO> & { type: string })\n    )[]\n  ) {\n    const requirePropForType = {\n      country: [\"country_code\"],\n      province: [\"country_code\", \"province_code\"],\n      city: [\"country_code\", \"province_code\", \"city\"],","sourceCodeStart":2119,"sourceCodeEnd":2155,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/fulfillment/src/services/fulfillment-module-service.ts#L2119-L2155","documentation":"Thrown when updating a shipping option's rules with IDs that do not belong to (or do not exist on) that shipping option. The module computes a set difference between the rule IDs you passed and the option's actual rules; any extra ID is rejected as NOT_FOUND.","triggerScenarios":"updateShippingOptions with a rules array containing { id: 'sor_xxx' } where that rule ID does not exist on the given shipping option — typo'd IDs, rules deleted by a concurrent update, or IDs copied from another option.","commonSituations":"UI editing rules where the client sends stale rule IDs; syncing rule sets between environments; concurrent admin edits.","solutions":["Fetch the option's current rules first and only include IDs present in updateShippingOptions(id).rules","For new rules, omit the id field so they are created instead of matched","Re-fetch fresh rule IDs before each update (avoid caching them in client state)"],"exampleFix":"// before\nawait service.updateShippingOptions([{ id: soId, rules: [{ id: 'sor_stale', operator: 'eq', attribute: 'iso', value: 'dk' }] }])\n// after\nconst [option] = await service.listShippingOptions({ id: soId })\nconst validIds = new Set(option.rules.map((r) => r.id))\nconst rules = payload.rules.map((r) => (r.id && !validIds.has(r.id) ? { ...r, id: undefined } : r))\nawait service.updateShippingOptions([{ id: soId, rules }])","handlingStrategy":"validation","validationCode":"const [option] = await fulfillmentService.listShippingOptions({ id: update.id })\nconst valid = new Set(option.rules.map((r) => r.id))\nconst safeRules = update.rules.filter((r) => !r.id || valid.has(r.id))","typeGuard":"const isExistingRuleId = (id: string | undefined, valid: Set<string>): boolean => !id || valid.has(id)","tryCatchPattern":"catch (e) { if (/rules does not exist/i.test(e.message)) { /* refetch rules and retry without stale ids */ } }","preventionTips":["Send rule id only when updating a known rule; omit id to create","Refetch the option's rules right before editing"],"tags":["fulfillment","shipping-options","rules","not-found"],"backgroundTag":"stale-reference-id","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}