medusajs/medusa · error · MedusaError

Rule operator must be a string

Error message

Rule operator must be a string

What it means

Within validateRule, the rule's operator must be a string. Non-string operators (numbers, objects) throw INVALID_DATA before the supported-operator check runs.

Source

Thrown at packages/modules/fulfillment/src/utils/utils.ts:114

 * @param rule
 */
export function validateRule(rule: Record<string, unknown>): boolean {
  if (!rule.attribute || !rule.operator || !rule.value) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      "Rule must have an attribute, an operator and a value"
    )
  }

  if (!isString(rule.attribute)) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      "Rule attribute must be a string"
    )
  }

  if (!isString(rule.operator)) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      "Rule operator must be a string"
    )
  }

  if (!availableOperators.includes(rule.operator as RuleOperator)) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Rule operator ${
        rule.operator
      } is not supported. Must be one of ${availableOperators.join(", ")}`
    )
  }

  if (rule.operator === RuleOperator.IN || rule.operator === RuleOperator.NIN) {
    if (!Array.isArray(rule.value)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Pass operator as one of the string literals ('eq','neq','gt','gte','lt','lte','in','nin')
  2. Normalize input at the API boundary

Example fix

// before
rules: [{ attribute: 'iso', operator: 1, value: 'dk' }]
// after
rules: [{ attribute: 'iso', operator: 'eq', value: 'dk' }]
Defensive patterns

Strategy: type-guard

Type guard

const hasStringOperator = (r: any): boolean => typeof r?.operator === 'string'

Prevention

When it happens

Trigger: Passing operator as an enum-like numeric code or an object from a query parser (e.g. operator[something]).

Common situations: Form encoders producing nested objects; mapping external condition codes directly to operator.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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