krisk/Fuse · error · Error

Property 'weight' in key '${key}' must be a positive integer

Error message

Property 'weight' in key '${key}' must be a positive integer

What it means

Thrown by createKey when an object-form key declares a 'weight' (other than undefined) whose value is <= 0. Weights scale per-key scores and must be positive; a zero or negative weight would either zero out the field's contribution entirely or invert score ordering, so it is rejected at key normalization time.

Source

Thrown at src/tools/KeyStore.ts:67

    | null = null

  if (isString(key) || isArray(key)) {
    src = key
    path = createKeyPath(key)
    id = createKeyId(key)
  } else {
    if (!hasOwn.call(key, 'name')) {
      throw new Error(ErrorMsg.MISSING_KEY_PROPERTY('name'))
    }

    const name = key.name
    src = name

    if (hasOwn.call(key, 'weight') && key.weight !== undefined) {
      weight = key.weight

      if (weight <= 0) {
        throw new Error(ErrorMsg.INVALID_KEY_WEIGHT_VALUE(createKeyId(name)))
      }
    }

    path = createKeyPath(name)
    id = createKeyId(name)
    getFn = key.getFn ?? null
  }

  return { path: path!, id: id!, weight, src: src!, getFn }
}

export function createKeyPath(key: string | string[]): string[] {
  return isArray(key) ? key : key.split('.')
}

export function createKeyId(key: string | string[]): string {
  return isArray(key) ? key.join('.') : key
}

View on GitHub (pinned to edf2fb608e)

Solutions

  1. Give the key a positive integer weight, e.g. { name: 'title', weight: 20 }
  2. Remove the 'weight' property (or set it to undefined) to use the default weight of 1
  3. Fix the computation that produced the weight — dynamic weights derived from division or subtraction can yield 0 or negatives
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/tools/KeyStore.ts:67 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of krisk/Fuse@edf2fb608e (2026-09-02). Data as JSON: /api/errors/c395d28ca91bf1aa. Report an issue: GitHub.