-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust: Overhaul errors to use an enum #781
Conversation
match self.0.code { | ||
sys::FizzyErrorCode_FIZZY_SUCCESS => None, | ||
sys::FizzyErrorCode_FIZZY_ERROR_MALFORMED_MODULE => { | ||
Some(Error::MalformedModule(self.message())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also think getting rid of code()
and message()
and only having error()
.
9c9b2d2
to
bf89d44
Compare
@@ -40,6 +40,29 @@ mod sys; | |||
use std::ffi::CString; | |||
use std::ptr::NonNull; | |||
|
|||
#[derive(Eq, PartialEq, Debug, Clone)] | |||
pub enum Error { | |||
MalformedModule(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer using &str
with a lifetime, but maybe better not getting FIzzyErrorBox
involved into lifetime management?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what this mean.
Codecov Report
@@ Coverage Diff @@
## master #781 +/- ##
==========================================
- Coverage 99.35% 99.28% -0.07%
==========================================
Files 86 86
Lines 13174 13192 +18
==========================================
+ Hits 13089 13098 +9
- Misses 85 94 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
|
451be0c
to
3da0019
Compare
InvalidModule(String), | ||
InstantiationFailed(String), | ||
Other(String), | ||
FunctionNotFound, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top 4 errors are 1-to-1 match with the C ones, and the below 5 are Rust specific.
28ce19b
to
d580d7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me.
bb220c3
to
8544c58
Compare
Mirror error codes from C API
assert_eq!(validate(&[]).err().unwrap(), "invalid wasm module prefix"); | ||
assert_eq!( | ||
validate(&[]).err().unwrap(), | ||
Error::MalformedModule("invalid wasm module prefix".to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider defining expected error once instead of repeating Error::MalformedModule("invalid wasm module prefix".to_string()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(only for this case where error message is repeated. Repeating just an enum like Error::InvalidMemoryOffsetOrSize
is fine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I'm slightly leaning towards keeping it as-is because it is easier to change if underlying errors change, and it is only an error message.
@@ -40,6 +40,29 @@ mod sys; | |||
use std::ffi::CString; | |||
use std::ptr::NonNull; | |||
|
|||
#[derive(Eq, PartialEq, Debug, Clone)] | |||
pub enum Error { | |||
MalformedModule(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea what this mean.
The top 5 errors are matching the C API: https://github.com/wasmx/fizzy/blob/master/include/fizzy/fizzy.h#L24-L39 The |
Depends on #783.
Based on #677.