add thiserror, split error::Error into different modules#324
Conversation
ddf1800 to
d1bb37b
Compare
| ArgumentMissing(WitnessName), | ||
| ArgumentTypeMismatch(WitnessName, ResolvedType, ResolvedType), | ||
| LexerError(String), | ||
| ParsingError(crate::parse::Error), |
There was a problem hiding this comment.
I was expecting to see ParsingError(#[from] crate::parse::Error), is there a reason it's not done this way?
There was a problem hiding this comment.
I'm leaving the old Display implementation and not migrating to thiserror to keep the changes minimal. Also, I hope that we remove this enum completely, so I think it's fine to leave it as is.
| use crate::types::{AliasedType, BuiltinAlias, TypeConstructible, UIntType}; | ||
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
| pub struct SyntaxError { |
There was a problem hiding this comment.
| pub struct SyntaxError { | |
| pub struct SyntaxErrorInfo { |
Perhaps better to use a name that doesn't end in Error so that it is not confused with an error that can be returned
| SyntaxError(#[from] SyntaxError), | ||
|
|
||
| #[error("Incompatible match arms: {0}, {1}")] | ||
| IncompatibleMatchArms(MatchPattern, MatchPattern), |
There was a problem hiding this comment.
| IncompatibleMatchArms(MatchPattern, MatchPattern), | |
| IncompatibleMatchArms{ left: MatchPattern, right: MatchPattern}, |
More of a personal preference, but I prefer using the named struct pattern when the inner members are not obvious
There was a problem hiding this comment.
I would also like to implement this in future PRs to keep the changes minimal. The plan is to also refactor these errors to contain more information (additional spans, notes, etc.)
We moved SyntaxError as a separate struct so we can make custom Display implementation
also add inside test reexport for parse::Error so there wouldn't be conflicts after deleteting Error variants
This also made change inside some modules to use ast::Error instead of error::Error.
d1bb37b to
c30d9ca
Compare
|
|
||
| impl From<simplicity::elements::hex::Error> for Error { | ||
| fn from(error: simplicity::elements::hex::Error) -> Self { | ||
| Self::CannotParse(error.to_string()) |
There was a problem hiding this comment.
In e656be0:
In general I don't like these From impls -- it is better to make the user write .map_err(some_explicit_conversion)? rather than just ?, because if you have the single-character ? available, you're really discouraged from adding more error context at call sides.
Then in specific, I really don't like these From impls which convert to strings and then shove the strings into a generic enum variant.
| FunctionUndefined(FunctionName), | ||
|
|
||
| #[error("Failed to compile to Simplicity: {0}")] | ||
| CannotCompile(String), |
There was a problem hiding this comment.
In 39ff893:
This is used in only one place - to indicate that the use keyword is not yet supported. We should have a dedicated error variant for this.
| BitStringPow2(usize), | ||
|
|
||
| #[error("{0}")] | ||
| Generic(String), |
There was a problem hiding this comment.
In 39ff893:
What is this for? It is unused in this commit. Can it hold a Box<dyn std::error::Error> rather than a string?
| } | ||
|
|
||
| impl From<crate::num::ParseIntError> for Error { | ||
| fn from(error: crate::num::ParseIntError) -> Self { |
There was a problem hiding this comment.
In 39ff893:
My same complaint about the From impls in the last commit apply here.
|
Rather than reviewing all these commits, let me try to provide some general guidance:
|
|
I understand that you're violating many of these guidelines to keep the changes minimal so that each PR is reviewable. Would it be possible to change only some errors at a time, but to do so completely, to create minimal PRs? For example, I think any error type which is currently a |
|
Thanks for the guidance!
Okay, I will try this first. Basically, I wanted to do most of this after this PR, but after your comments, I think doing it before makes more sense. |
Implementing the first step of the error refactor issue: #204 (comment).
I tried to keep the changes minimal, so I did not refactor RichError completely. Also, keep in mind that we will most likely remove
error::Errorand replace RichError with something more like a Diagnostic.