Skip to content
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

Merged
merged 9 commits into from
May 24, 2022
Merged

rust: Overhaul errors to use an enum #781

merged 9 commits into from
May 24, 2022

Conversation

axic
Copy link
Member

@axic axic commented Apr 7, 2021

Depends on #783.
Based on #677.

bindings/rust/src/lib.rs Outdated Show resolved Hide resolved
match self.0.code {
sys::FizzyErrorCode_FIZZY_SUCCESS => None,
sys::FizzyErrorCode_FIZZY_ERROR_MALFORMED_MODULE => {
Some(Error::MalformedModule(self.message()))
Copy link
Member Author

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().

@axic axic force-pushed the rust-new-error branch 2 times, most recently from 9c9b2d2 to bf89d44 Compare April 7, 2021 19:06
@@ -40,6 +40,29 @@ mod sys;
use std::ffi::CString;
use std::ptr::NonNull;

#[derive(Eq, PartialEq, Debug, Clone)]
pub enum Error {
MalformedModule(String),
Copy link
Member Author

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?

Copy link
Collaborator

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
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #781 (6f99c4a) into master (9ae449c) will decrease coverage by 0.06%.
The diff coverage is 90.42%.

❗ Current head 6f99c4a differs from pull request most recent head ad96b18. Consider uploading reports for the commit ad96b18 to get more accurate results

@@            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     
Flag Coverage Δ
rust 98.73% <90.42%> (-0.87%) ⬇️
spectests 89.98% <ø> (ø)
unittests 99.21% <ø> (ø)
unittests-32 99.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bindings/rust/src/lib.rs 99.01% <90.42%> (-0.89%) ⬇️

@axic axic force-pushed the rust-rich-error branch 2 times, most recently from 451be0c to 3da0019 Compare April 9, 2021 16:35
Base automatically changed from rust-rich-error to master April 9, 2021 17:24
@axic axic force-pushed the rust-new-error branch from bf89d44 to 028d869 Compare April 9, 2021 18:01
@axic axic changed the base branch from master to capi-errors April 9, 2021 18:01
@axic axic force-pushed the rust-new-error branch from 028d869 to 7b98d59 Compare April 9, 2021 18:11
@axic axic marked this pull request as ready for review April 9, 2021 18:12
@axic axic requested review from gumb0 and chfast April 9, 2021 18:12
InvalidModule(String),
InstantiationFailed(String),
Other(String),
FunctionNotFound,
Copy link
Member Author

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.

Base automatically changed from capi-errors to master April 12, 2021 10:40
@axic axic force-pushed the rust-new-error branch 2 times, most recently from 28ce19b to d580d7e Compare April 12, 2021 10:47
Copy link
Collaborator

@gumb0 gumb0 left a 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.

@axic axic force-pushed the rust-new-error branch from d580d7e to 374494a Compare May 6, 2022 19:03
@axic axic force-pushed the rust-new-error branch from 374494a to 021b276 Compare May 23, 2022 09:16
@axic axic mentioned this pull request May 23, 2022
@axic axic force-pushed the rust-new-error branch 3 times, most recently from bb220c3 to 8544c58 Compare May 23, 2022 23:22
@axic axic requested a review from gumb0 May 23, 2022 23:25
@axic axic force-pushed the rust-new-error branch from 8544c58 to ad96b18 Compare May 23, 2022 23:33
assert_eq!(validate(&[]).err().unwrap(), "invalid wasm module prefix");
assert_eq!(
validate(&[]).err().unwrap(),
Error::MalformedModule("invalid wasm module prefix".to_string())
Copy link
Collaborator

@gumb0 gumb0 May 24, 2022

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()

Copy link
Collaborator

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)

Copy link
Member Author

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),
Copy link
Collaborator

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.

@axic
Copy link
Member Author

axic commented May 24, 2022

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 String parts means it can have a string explainer.

@axic axic merged commit 513b073 into master May 24, 2022
@axic axic deleted the rust-new-error branch May 24, 2022 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants