Skip to content

Commit 9d6151f

Browse files
committed
feat(codec): add TypeError::InvalidValue variant
Add InvalidValue { value: i32 } to TypeError for cases where bytes were read successfully but the decoded value is not a recognized enum variant. This replaces the misleading use of UnexpectedEof for invalid enum IDs.
1 parent 3fb8b48 commit 9d6151f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: src/types.rs
3+
expression: "format!(\"{}\", TypeError::InvalidValue { value: 42 })"
4+
---
5+
invalid value: 42

src/types.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ pub enum TypeError {
6565
/// Invalid UTF-8 in a string.
6666
#[error("invalid UTF-8: {0}")]
6767
InvalidUtf8(#[from] std::string::FromUtf8Error),
68+
69+
/// Value was successfully read but is not a recognized variant.
70+
#[error("invalid value: {value}")]
71+
InvalidValue {
72+
/// The unrecognized value that was read.
73+
value: i32,
74+
},
6875
}
6976

7077
/// Reads a VarInt-length-prefixed UTF-8 string from `buf`.
@@ -397,6 +404,10 @@ mod tests {
397404
"unexpected_eof",
398405
format!("{}", TypeError::UnexpectedEof { need: 16, have: 4 })
399406
);
407+
insta::assert_snapshot!(
408+
"invalid_value",
409+
format!("{}", TypeError::InvalidValue { value: 42 })
410+
);
400411
}
401412

402413
#[test]

0 commit comments

Comments
 (0)