CosmicHorrorDev / vdf-rs

VDF parsing and (de)serialization for Rust
Apache License 2.0
31 stars 3 forks source link

`unreachable!()` code is most certainly reachable #45

Closed CosmicHorrorDev closed 10 months ago

CosmicHorrorDev commented 11 months ago

The following code hits an unreachable!() call in keyvalues-serde

use std::collections::BTreeMap;

fn main() {
    let _ = keyvalues_serde::to_string(&BTreeMap::<(), ()>::new());
}

Using an unreachable!() was very naive in hindsite. It's pretty trivial to feed the serializer a data format that doesn't match what VDF can represent. The library should return an error here indicating that it doesn't match the expected format

In this case it almost matched the expected format expect it didn't provide a top level key. This will likely be the most common error to see, so we should ideally try to detect this case and emit an error mentioning the _with_key() family of functions that should do the trick for most people