Conversation
5b9fb26 to
046564b
Compare
ed255
left a comment
There was a problem hiding this comment.
I've taken an initial look at the PR and left a lot of comments to discuss details :)
src/error.rs
Outdated
| #[error("std::io::Error: {0}")] | ||
| IOError(#[from] std::io::Error), | ||
| #[error("anyhow::Error: {0}")] | ||
| Anyhow(#[from] anyhow::Error), |
There was a problem hiding this comment.
It would be interesting if we can distinguish plonky2 errors (which are anyhow::Error) from other anyhow::Errors). But perhaps that would require a lot of boilerplate in the code :/
src/error.rs
Outdated
| #[error("{0} {1} is over the limit {2}")] | ||
| MaxLength(String, usize, usize), | ||
| #[error("{0} amount of {1} should be {1} but it's {2}")] | ||
| DiffAmount(String, String, usize, usize), |
There was a problem hiding this comment.
Did you consider naming the fields so that the error creation is more clear?
For example:
DiffAmount{object: String, unit: String, expect: usize, found: usize}The same applies to other error cases that have several fields
src/frontend/mod.rs
Outdated
| match (args).first() { | ||
| Some(OperationArg::Statement(s)) if args.len() == 1 => Ok(s.predicate().clone()), | ||
| _ => Err(anyhow!("Invalid arguments to copy operation: {:?}", args)), | ||
| _ => Err(Error::OpInvalidArgs("copy".to_string())), |
There was a problem hiding this comment.
oops, the args is not captured by the error. I see that we were not doing that in some of the following errors before.
src/error.rs
Outdated
|
|
||
| // Other | ||
| #[error("{0}")] | ||
| Custom(String), |
There was a problem hiding this comment.
Could we remove this Custom entry and use anyhow instead?
This way we can use the anyhow macro for convenience and it should get converted into Error::Anyhow.
|
One major thing that I find missing from the proposal is that with this change we're losing the backtrace in the errors. I see in the documentation of |
e4c8b9e to
d945379
Compare
|
Agree with everything, for context (@ax0 ), we had a call with @ed255 , and he is going to try adding macros for defining & returning the errors (defined by thiserror), while also returning the backtrace. Update on the PR: got rid of the git-conflicts while rebasing the PR branch to last |
d945379 to
92fcdf3
Compare
|
I'm currently working on this PR, although I'm not finished yet. Here are my goals:
|
- Include backtraces in the errors we generate. To get this we can't just return a literal enum, because the backtrace requires a call. - Related to the previous point: add methods to create errors so we can include the backtrace conveniently without changing too much the syntax. So instead of `Err(Error::KeyNotFound(key))` (literal enum) it will be `Err(Error::key_not_found(key))` (method call) - Each error should be local to its scope, and each scope should only return its own error. - The merkle tree should return `TreeError` and not Error - The middleware should return `MiddlewareError` and not Error - With a global Error we can't easily include backend/frontend types in the error fields, so declare a `BackendError` and a `FrontendError` and follow the pattern from the previous point - The Pod traits should be able to return backend errors and will be used in the frontend; for that we change them to use trait object Error: `dyn std::error::Error`
0c15d87 to
d0e0258
Compare
|
Topics to discuss:
|
|
@arnaucube could you please review the new commits? |
|
Regarding
Conceptually I prefer BUT (1): when using it, we will end up doing the renaming alias to BUT (2): the case mentioned at 'BUT (1)' only happens very few times, so maybe it's fine to use So with this, unless we find other reasonings towards the other direction, I'm more inclined to use the (edited the comment to add the 'But (2)' after diving more into the last version of the branch) |
| backends::plonky2::{ | ||
| basetypes::D, | ||
| circuits::common::{CircuitBuilderPod, ValueTarget}, | ||
| error::BackendResult, |
There was a problem hiding this comment.
since you moved primitives/merkletree.rs into primitives/merkletree/mod.rs, maybe we can move also this file primitives/merkeltree_circuit.rs into primitives/merkletree/circuit.rs too?
src/frontend/error.rs
Outdated
| #[error(transparent)] | ||
| Tree(#[from] crate::backends::plonky2::primitives::merkletree::error::TreeError), |
There was a problem hiding this comment.
is this one used? I've tried removing it and seems to not be used. I was trying this bcs I was thinking if maybe we could avoid using the TreeError since it could be 'embedded' in the backend::Error already.
arnaucube
left a comment
There was a problem hiding this comment.
LGTM!
I can not mark it as 'approve' in the GitHub UI since I opened the PR, but everything looks good from my side ^^
This PR migrates from using
anyhowtothiserroras agreed in #190 . Contains an initial commit that does the migration, but not as a final version to be merged.@ax0 @ed255 feel free to update it with commits polishing the error messages. All the occurrences of the string
Error::Custom(format!, are error messages that were not used more than once an it was not clear if a specific error type was needed for them. Maybe how we can approach it is that if the error message will not be used in the upper layers, it can be as aError::Custom(String), as it was before with anyhow.Once ready, this will resolve #190.