{"record":{"id":"4bd266564bc3a627","repo":"clockworklabs/SpacetimeDB","slug":"too-many-elements","errorCode":null,"errorMessage":"too many elements","messagePattern":"too many elements","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/server/runtime.ts","lineNumber":1425,"sourceCode":"        },\n      } as PointIndex<any, any>;\n    } else {\n      // numColumns != 1\n      const isCompleteScalarKey = (range: any[]): boolean => {\n        // Preserve the point-scan path only for complete scalar keys.\n        // A complete key with a Range in the final position is still a range\n        // scan over that column with equality over the preceding prefix.\n        return (\n          range.length === numColumns &&\n          !(range[range.length - 1] instanceof Range)\n        );\n      };\n\n      const serializeRange = (\n        buffer: ResizableBuffer,\n        range: any[]\n      ): IndexScanArgs => {\n        if (range.length > numColumns) throw new TypeError('too many elements');\n\n        BINARY_WRITER.reset(buffer);\n        const writer = BINARY_WRITER;\n        const prefix_elems = range.length - 1;\n        for (let i = 0; i < prefix_elems; i++) {\n          indexSerializers[i](writer, range[i]);\n        }\n        const rstartOffset = writer.offset;\n        const term = range[range.length - 1];\n        const serializeTerm = indexSerializers[range.length - 1];\n        if (term instanceof Range) {\n          const writeBound = (bound: Bound<any>) => {\n            const tags = { included: 0, excluded: 1, unbounded: 2 };\n            writer.writeU8(tags[bound.tag]);\n            if (bound.tag !== 'unbounded') serializeTerm(writer, bound.value);\n          };\n          writeBound(term.from);\n          const rstartLen = writer.offset - rstartOffset;","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-typescript/src/server/runtime.ts#L1407-L1443","documentation":"For a multi-column ranged index, filter()/delete() accept a prefix/range array of at most numColumns elements: all but the last are equality values and the last may be a Range bound. serializeRange throws TypeError('too many elements') when the array is longer than the index's column count: you cannot constrain more columns than the index covers.","triggerScenarios":"Calling filter([a, b, c]) on a two-column index; passing a full key plus a Range (numColumns + 1 elements); stale queries after a column was dropped from the index definition.","commonSituations":"Index narrowed from three columns to two without updating range queries; building the filter array dynamically with an off-by-one; assuming extra elements are silently ignored.","solutions":["Limit the argument to at most the index's column count: filter([a, b]) or filter([a, range]) for a 2-column index","Update every filter/delete call site for an index whenever its column list changes","When building arrays dynamically, assert length <= index column count before calling"],"exampleFix":"// before (ranged index on [a, b])\nconst rows = ctx.db.t.idx.filter([a, b, someRange]); // 3 elements > 2 columns\n\n// after: equality on `a`, range over `b`\nconst rows = ctx.db.t.idx.filter([a, someRange]);","handlingStrategy":"validation","validationCode":"// ranged index covering N columns: at most N elements (all but last are equalities)\nfunction assertRangeArity(range: unknown[], numColumns: number): void {\n  if (range.length > numColumns) {\n    throw new Error(`range has ${range.length} elements but index covers only ${numColumns} columns`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the shape: equality prefix plus optionally one Range on the final indexed column, never more elements than indexed columns","Update every filter/delete call site when an index's column list changes","Assert dynamic array lengths before calling filter/delete in query-builder code"],"tags":["index","database","query","range","typescript"],"backgroundTag":"invalid-index-query","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}