{"record":{"id":"79962271405f2950","repo":"clockworklabs/SpacetimeDB","slug":"unexpected-error-from-datastore-delete-by-index-s-799622","errorCode":null,"errorMessage":"unexpected error from `datastore_delete_by_index_scan_range_bsatn`: {e}","messagePattern":"unexpected error from `datastore_delete_by_index_scan_range_bsatn`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings/src/table.rs","lineNumber":967,"sourceCode":"    /// though at present no such constraints exist.\n    pub fn delete<B, K>(&self, b: B) -> u64\n    where\n        B: IndexScanRangeBounds<IndexType, K>,\n    {\n        let index_id = Idx::index_id();\n        if const { is_point_scan::<Idx, B, _, _>() } {\n            b.with_point_arg(|point| {\n                sys::datastore_delete_by_index_scan_point_bsatn(index_id, point)\n                    .unwrap_or_else(|e| {\n                        panic!(\"unexpected error from `datastore_delete_by_index_scan_point_bsatn`: {e}\")\n                    })\n                    .into()\n            })\n        } else {\n            let args = b.get_range_args();\n            let (prefix, prefix_elems, rstart, rend) = args.args_for_syscall();\n            sys::datastore_delete_by_index_scan_range_bsatn(index_id, prefix, prefix_elems, rstart, rend)\n                .unwrap_or_else(|e| panic!(\"unexpected error from `datastore_delete_by_index_scan_range_bsatn`: {e}\"))\n                .into()\n        }\n    }\n}\n\n/// Performs a ranged scan using the range arguments `B` in `Tbl` using `Idx`.\n///\n/// The type parameter `K` is either `()` or [`SingleBound`]\n/// and is used to workaround the orphan rule.\nfn filter<Tbl, Idx, IndexType, B, K>(b: B) -> impl Iterator<Item = Tbl::Row>\nwhere\n    Tbl: Table,\n    Idx: Index,\n    B: IndexScanRangeBounds<IndexType, K>,\n{\n    let index_id = Idx::index_id();\n\n    let iter = if const { is_point_scan::<Idx, B, _, _>() } {","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings/src/table.rs#L949-L985","documentation":"Raised inside a SpacetimeDB reducer when the `datastore_delete_by_index_scan_range_bsatn` host syscall returns an errno the bindings do not consider possible for a ranged index delete. The bindings call `RangedIndex::delete(range)` (e.g. `ctx.db.user().dogs_and_name().delete(25u64..)`), encode the range args, and panic on any non-OK status. In practice this means the module and the database host disagree about the index or the module binary is talking to an incompatible host, not that your range logic is wrong.","triggerScenarios":"Calling `RangedIndex::delete` with a non-point range (e.g. `25u64..`, `(25u64, \"J\"..\"K\")`) when the host returns an unexpected errno: publishing a module whose index definitions no longer match the live database schema, mixing an older `spacetimedb-bindings` crate with a newer server, or a host-internal error while scanning/deleting rows.","commonSituations":"Version skew between the spacetimedb toolchain (`spacetime publish`) and the bindings crate pinned in Cargo.toml; republishing after changing an index's columns without a clean publish; CI builds that reuse a stale module against a migrated database.","solutions":["Republish the module so the wasm binary and the database schema/indexes are rebuilt together: `spacetime publish <db> --clear-data` (or a fresh database) to rule out schema drift.","Align versions: make the `spacetimedb-bindings` version in your module's Cargo.toml match the server/CLI version you deploy against.","Reproduce with a minimal reducer that only performs the ranged delete to confirm the range arguments themselves are well-formed.","If it persists with matching versions, capture the `{e}` errno in the panic message and report it as a SpacetimeDB issue — this panic marks a host invariant violation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Reducer: wrap the ranged delete so an unexpected host error is logged,\n// then deliberately abort the transaction (panic = rollback in SpacetimeDB).\nlet result = std::panic::catch_unwind(|| {\n    ctx.db.user().dogs_and_name().delete(25u64..)\n});\nif let Err(panic) = result {\n    log::error!(\"ranged delete failed: {panic:?}\");\n    panic!(); // or convert into a reducer error path\n}","preventionTips":["Keep the spacetimedb-bindings crate version locked to the server/CLI version you deploy against.","Always republish the module after changing table or index definitions; never reuse an old wasm against a migrated schema.","Smoke-test every ranged delete/filter in a staging database before shipping the reducer."],"tags":["spacetimedb","reducer-panic","index-delete","host-syscall","version-skew"],"backgroundTag":"host-syscall-unexpected-error","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}