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

"improve: error msgs and handling" #209

Merged
merged 10 commits into from
Oct 29, 2024
Merged

Conversation

crypdoughdoteth
Copy link
Contributor

Closes #26 - removes panics in favor of clear error messages and improves error handling in some places

@crypdoughdoteth
Copy link
Contributor Author

Quick question: in mast/mod.rs/42:13: should the constructor of ExprMonoInfo panic?

Copy link
Contributor

@mimoo mimoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks so much! I'll merge this one but feel free to address the comments in another PR :)

src/error.rs Show resolved Hide resolved
src/inputs.rs Show resolved Hide resolved
src/inputs.rs Show resolved Hide resolved
src/inputs.rs Show resolved Hide resolved
src/inputs.rs Outdated Show resolved Hide resolved
@mimoo
Copy link
Contributor

mimoo commented Oct 23, 2024

actually I see this is a draft, so let me know when it's good to be merged!

@crypdoughdoteth
Copy link
Contributor Author

Panics are now limited to circuit_writer.rs and some constructors

@crypdoughdoteth crypdoughdoteth marked this pull request as ready for review October 23, 2024 23:24
@crypdoughdoteth crypdoughdoteth changed the title "PR Init (error msgs and handling): sample changes for feedback" "improve: error msgs and handling" Oct 23, 2024
}

terms
Ok(terms)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary @katat ?

src/error.rs Outdated Show resolved Hide resolved
Err(Error::new(
"constraint-generation",
ErrorKind::AssertTypeMismatch("rhs", rhs),
span,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think UnexpectedError is still good here, as I don't think we should run into these things (the type checker will catch that before we hit this place)

Copy link
Contributor Author

@crypdoughdoteth crypdoughdoteth Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue that I ran into here is that I wanted to also include res_info.typ in the error message just like in the panic version. format!() returns String and UnexpectedError requires &'static str as its tagged field. Borrowing the String does not last for 'static unless I leak the allocation. In order to get around this, I created this new error variant. The alternative was a slightly more opaque error message. I'm not sure if this is the right thing per se, but worth discussing briefly

src/parser/types.rs Outdated Show resolved Hide resolved
src/type_checker/checker.rs Show resolved Hide resolved
@mimoo mimoo mentioned this pull request Oct 25, 2024
.clone();

// and is mutable
if !lhs_info.mutable {
return Err(self.error(ErrorKind::AssignmentToImmutableVariable, expr.span));
if let Some(lhs_info) = lhs_info {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why is lhs_info still an option here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out what went wrong here: I didn't handle the Result with ? produced from get_type_info()

.get_type_info(&lhs_name)
.or_else(|_| {
Err(self.error(ErrorKind::UnexpectedError("variable not found"), expr.span))
})?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want ok_or here instead

@mimoo
Copy link
Contributor

mimoo commented Oct 25, 2024

Lgtm! Thanks so much for the PR!

I'll let @katat merge after looking at #209 (comment)

@katat
Copy link
Collaborator

katat commented Oct 28, 2024

Looks good, thanks!
Btw, any ideas on why the test CI failed? @crypdoughdoteth

@crypdoughdoteth
Copy link
Contributor Author

CI should be green now 🫡

@mimoo mimoo merged commit 2a09ba0 into zksecurity:main Oct 29, 2024
1 check passed
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.

Replace all panics with cleaner error
3 participants