SpacetimeDB
SpacetimeDB copied to clipboard
Don't panic in `datastore_index_scan_range_bsatn` on invalid ranges
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:
- does not error, and immediately returns zero values.
- This may (probably should) inject a warning into the module's logs.
- is equivalent to a scan on
(Exclusive(y), Inclusive(x))(likey..x, but respecting the inclusiveness of the bounds when swapping them). - 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.