{"record":{"id":"4403b7584960616b","repo":"gatsbyjs/gatsby","slug":"bad-value-at-path-inspect-fieldvalue","errorCode":null,"errorMessage":"Bad value at ${path}: ${inspect(fieldValue)}","messagePattern":"Bad value at (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/datastore/lmdb/query/create-index.ts","lineNumber":192,"sourceCode":"function prepareIndexKeys(\n  node: IGatsbyNode,\n  resolvedFields: { [field: string]: unknown } | undefined,\n  indexName: string,\n  indexFields: IndexFields\n): { keys: Array<IndexKey>; multiKeyFields: Array<string> } {\n  // TODO: use index id vs index name (shorter)\n  const indexKeyElements: Array<Array<IndexFieldValue>> = []\n  const multiKeyFields: Array<string> = []\n\n  indexKeyElements.push([indexName])\n  for (const dottedField of indexFields.keys()) {\n    const fieldValue = resolveFieldValue(dottedField, node, resolvedFields)\n    let indexFieldValue = jsValueToLmdbKey(fieldValue)\n\n    // Got value that can't be stored in lmdb key\n    if (typeof indexFieldValue === `undefined`) {\n      const path = `${node.internal.type}.${dottedField} (id: ${node.id})`\n      throw new Error(`Bad value at ${path}: ${inspect(fieldValue)}`)\n    }\n    indexFieldValue = Array.isArray(indexFieldValue)\n      ? indexFieldValue.flat() // FIXME\n      : [indexFieldValue]\n\n    indexKeyElements.push(indexFieldValue)\n\n    if (indexFieldValue.length > 1) {\n      multiKeyFields.push(dottedField)\n    }\n  }\n  indexKeyElements.push([node.internal.counter])\n\n  return { keys: cartesianProduct(...indexKeyElements), multiKeyFields }\n}\n\nasync function lockIndex(\n  context: IIndexingContext,","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/datastore/lmdb/query/create-index.ts#L174-L210","documentation":"LMDB indexes serialise each indexed field via `jsValueToLmdbKey`. If a field value cannot be converted to a valid key (returns `undefined` — e.g. a function, symbol, or unrecognised object), index insertion aborts with the node type, dotted field path, and node id. This protects index integrity rather than writing a corrupt key.","triggerScenarios":"A node has a field used in a filter/index whose value is a non-serialisable type (function, class instance, symbol, complex object not reduced to primitives).","commonSituations":"Source plugins returning rich objects/functions on fields that are then queried with a filter (which triggers indexing); custom resolvers attaching non-primitive metadata.","solutions":["Do not filter/sort on object/function fields; expose a scalar derived field instead.","In the source plugin, normalise the field to a primitive (string/number/boolean) or an array of primitives before node creation.","If the field is metadata-only, keep it out of `___gatsby` queryable surface."],"exampleFix":"// before: node.field = { toString() {...}, rank: () => 1 }  // indexed & filtered\n// after: node.fieldKey = \"computed-scalar\"; node.rank = 1   // index these instead","handlingStrategy":"validation","validationCode":"// Source-plugin side: ensure indexed fields are primitives or arrays of primitives.\nfunction assertIndexable(fieldValue, fieldPath) {\n  const ok = fieldValue === null ||\n  [\"string\", \"number\", \"boolean\"].includes(typeof fieldValue) ||\n  Array.isArray(fieldValue)\n  if (!ok) throw new Error(`Field ${fieldPath} is not indexable: ${typeof fieldValue}`)\n}\n","typeGuard":"type Indexable = string | number | boolean | null | Indexable[]\nfunction isIndexable(v: unknown): v is Indexable {\n  if (v === null || [\"string\", \"number\", \"boolean\"].includes(typeof v)) return true\n  if (Array.isArray(v)) return v.every(isIndexable)\n  return false\n}\n","tryCatchPattern":null,"preventionTips":["Do not expose functions/class instances/symbols on queryable fields.","Derive scalar index fields from rich objects in `onCreateNode`."],"tags":["datastore","lmdb","indexing","schema","internal"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}