Skip to content

Commit aef807b

Browse files
authored
Remove crash if fails to decode ModuleDef from bsatn (#55)
1 parent a5a48c2 commit aef807b

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

crates/lib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl std::fmt::Display for VersionTuple {
8888

8989
extern crate self as spacetimedb_lib;
9090

91+
//WARNING: Change this structure(or any of their members) is an ABI change.
9192
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, de::Deserialize, ser::Serialize)]
9293
pub struct TableDef {
9394
pub name: String,
@@ -170,6 +171,7 @@ impl ser::Serialize for ReducerArgsWithSchema<'_> {
170171
}
171172
}
172173

174+
//WARNING: Change this structure(or any of their members) is an ABI change.
173175
#[derive(Debug, Clone, Default, de::Deserialize, ser::Serialize)]
174176
pub struct ModuleDef {
175177
pub typespace: sats::Typespace,

crates/sats/src/bsatn/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a, 'de, R: BufReader<'de>> Deserializer<'a, R> {
1919

2020
impl de::Error for DecodeError {
2121
fn custom(msg: impl std::fmt::Display) -> Self {
22-
unreachable!("tried to create error `{msg}` but there shouldn't be any errors")
22+
DecodeError::Other(msg.to_string())
2323
}
2424

2525
fn unknown_variant_tag<'de, T: de::SumVisitor<'de>>(_tag: u8, _expected: &T) -> Self {

crates/sats/src/buffer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub enum DecodeError {
1111
BufferLength,
1212
InvalidTag,
1313
InvalidUtf8,
14+
Other(String),
1415
}
1516

1617
impl fmt::Display for DecodeError {
@@ -19,6 +20,7 @@ impl fmt::Display for DecodeError {
1920
DecodeError::BufferLength => f.write_str("data too short"),
2021
DecodeError::InvalidTag => f.write_str("invalid tag for enum"),
2122
DecodeError::InvalidUtf8 => f.write_str("invalid utf8"),
23+
DecodeError::Other(err) => f.write_str(err),
2224
}
2325
}
2426
}

0 commit comments

Comments
 (0)