gatsbyjs/gatsby · error · Error

Bad filter value for predicate ${filter.comparator}: ${inspe

Error message

Bad filter value for predicate ${filter.comparator}: ${inspect(filter.value)}

What it means

`toIndexFieldValue` converts a comparator value to an LMDB key. A non-null object is invalid for any single-value comparator, so the planner rejects it and prints the offending value via `inspect` along with the comparator name.

Source

Thrown at packages/gatsby/src/datastore/lmdb/query/filter-using-index.ts:689

 *
 * This method relies on ordered-binary format used by lmdb-store to persist keys
 * and assumes keys are composite and represented as arrays.
 *
 * Implementation detail: ordered-binary treats `null` as multipart separator within binary sequence
 */
function getValueEdgeAfter(value: IndexFieldValue): RangeEdgeAfter {
  return [value, BinaryInfinityPositive]
}
function getValueEdgeBefore(value: IndexFieldValue): RangeEdgeBefore {
  return [undefinedSymbol, value]
}

function toIndexFieldValue(
  filterValue: DbComparatorValue,
  filter: IDbFilterStatement
): IndexFieldValue {
  if (typeof filterValue === `object` && filterValue !== null) {
    throw new Error(
      `Bad filter value for predicate ${filter.comparator}: ${inspect(
        filter.value
      )}`
    )
  }
  return filterValue
}

function getIdentifier(entry: IIndexEntry): number | string {
  const id = entry.key[entry.key.length - 1]
  if (typeof id !== `number` && typeof id !== `string`) {
    const out = inspect(id)
    throw new Error(
      `Last element of index key is expected to be numeric or string id, got ${out}`
    )
  }
  return id
}

View on GitHub (pinned to 8b06340921)

Solutions

  1. Provide a primitive (or for `in`/`nin`, an array of primitives) to the comparator.
  2. If you need object equality, index a derived scalar key instead.

Example fix

// before
filter: { code: { eq: { value: "A1" } } }
// after
filter: { code: { eq: "A1" } }
Defensive patterns

Strategy: validation

Validate before calling

function assertScalarComparator(op, value) {
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
  throw new Error(`${op} value must be primitive, got object`)
  }
}

Type guard

function isComparatorPrimitive(v: unknown): v is string | number | boolean | null {
  return v === null || ["string", "number", "boolean"].includes(typeof v)
}

Prevention

When it happens

Trigger: Any indexed comparator receiving an object value, e.g. `{ eq: { foo: 1 } }` on an indexed scalar field.

Common situations: Generic/programmatic query builders passing through nested objects; source/transform producing object values on indexed fields.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/a55bce12a7420093. Report an issue: GitHub.