a Result or Option instead of a panic when the db/tree is corrupted or deliberately modified not by sled
thread 'main' panicked at '57 >= 83', /../github.com-1ecc6299db9ec823/sled-0.34.2/src/pagecache/snapshot.rs:325:9
https://github.com/spacejam/sled/blob/v0.34.2/src/pagecache/snapshot.rs#L325-L330
v0.34.2
rustc 1.45.2 (d3fb005a3 2020-07-31)
macOS Catalina
fn main() {
// this directory will be created if it does not exist
let path = "/tmp/yy";
let db = match sled::Config::new()
.temporary(false)
.path(path)
.mode(sled::Mode::LowSpace)
.use_compression(true)
.open()
{
Ok(db) => db,
Err(e) => {
eprintln!("{}", e);
std::process::exit(3);
}
};
Cargo.toml dependecies
[dependencies] sled = {version = "0.34.2", features = ["compression"] }
I was expecting to catch and handle the error in cases where the database has been corrupted, for testing this I modified the db file located under the defined path(/tmp/yy/db), I deleted some random rows and after running again the code it panics.
I agree that this should return an Error::Corruption instead of panicking. The right approach is to add a new randomized test that will corrupt files randomly and assert that the code never panics.
An immediate fix is being worked on in https://github.com/spacejam/sled/pull/1170 and will be released shortly