SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Don't panic in `datastore_index_scan_range_bsatn` on invalid ranges

Open gefjon opened this issue 1 month ago • 0 comments

A user report suggests that datastore_index_scan_range_bsatn will panic the host when passed a range where the end is greater than the start. std::collections::BTreeMap::range says it does this, so I guess we can't be too surprised, but it does seem like a silly and undesirable behavior.

We should decide whether a scan on a range x..y where x > y:

  1. does not error, and immediately returns zero values.
    • This may (probably should) inject a warning into the module's logs.
  2. is equivalent to a scan on (Exclusive(y), Inclusive(x)) (like y..x, but respecting the inclusiveness of the bounds when swapping them).
  3. returns an error which causes the module code to panic, but does not panic the host.
    • This replicates the Rust stdlib's behavior.

Then implement that behavior, and add a test somewhere which attempts such a scan without panicking.

gefjon avatar Nov 10 '25 15:11 gefjon