-
Notifications
You must be signed in to change notification settings - Fork 163
Library: add run_query_safe exposing parsing errors #3236
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -426,24 +426,38 @@ pub enum ArithmeticError { | |||
| UninstantiatedVar, | ||||
| } | ||||
|
|
||||
| /// Enum for parsing errors | ||||
| #[allow(dead_code)] | ||||
| #[non_exhaustive] | ||||
| #[derive(Debug)] | ||||
| pub enum ParserError { | ||||
| /// Backquoted String error found. | ||||
| BackQuotedString(usize, usize), | ||||
| /// IO Error error found. | ||||
| IO(IOError), | ||||
| /// Incomplete reduction error found. | ||||
| IncompleteReduction(usize, usize), | ||||
| /// Infinite float error found. | ||||
| InfiniteFloat(usize, usize), | ||||
| /// Invalid single quoted character found. | ||||
| InvalidSingleQuotedCharacter(char), | ||||
| /// Lexical error found. | ||||
| LexicalError(lexical::Error), | ||||
| /// Missing quote found. | ||||
| MissingQuote(usize, usize), | ||||
| /// Non prolog char found. | ||||
| NonPrologChar(usize, usize), | ||||
| /// BigInt parsing error found. | ||||
| ParseBigInt(usize, usize), | ||||
| /// Unexpected character found. | ||||
| UnexpectedChar(char, usize, usize), | ||||
| // UnexpectedEOF, | ||||
| /// UTF8 error found. | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These additional comments seem to mostly repeat the types? I would suggest leaving this out.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the Line 3 in 453a88f
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah OK, thank you, I was already wondering why this is suddenly part of the PR.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree they're superfluous but public enums seems to need to have documentation and I'd rather put them in than mess with the linter requirements. |
||||
| Utf8Error(usize, usize), | ||||
| } | ||||
|
|
||||
| impl ParserError { | ||||
| /// Get line number and column number for error. | ||||
| pub fn line_and_col_num(&self) -> Option<(usize, usize)> { | ||||
| match self { | ||||
| &ParserError::BackQuotedString(line_num, col_num) | ||||
|
|
@@ -458,6 +472,7 @@ impl ParserError { | |||
| } | ||||
| } | ||||
|
|
||||
| /// Return error as an atom | ||||
| pub fn as_atom(&self) -> Atom { | ||||
| match self { | ||||
| ParserError::BackQuotedString(..) => atom!("back_quoted_string"), | ||||
|
|
@@ -484,11 +499,13 @@ impl ParserError { | |||
| } | ||||
| } | ||||
|
|
||||
| /// Unexpected EOF error | ||||
| #[inline] | ||||
| pub fn unexpected_eof() -> Self { | ||||
| ParserError::IO(std::io::Error::from(ErrorKind::UnexpectedEof)) | ||||
| } | ||||
|
|
||||
| /// Is an unexpected EOF? | ||||
| #[inline] | ||||
| pub fn is_unexpected_eof(&self) -> bool { | ||||
| if let ParserError::IO(e) = self { | ||||
|
|
||||
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.
Was this already publicly reachable?1 Otherwise we might want to make this
#[non_exhaustive]so that we can add new variants without that being a breaking change.Footnotes
While it was already declared
pubit might not have been reachable until thepub usewas added in src/machine/lib_machine/mod.rs above ↩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.
As far as I know my change exposed it . Makes sense to add #[non_exhaustive], I'll add it to the PR.
Uh oh!
There was an error while loading. Please reload this page.
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.
Mh, looking at the error variants some more a lot of them have two usize that appear to be a line column number pair.
Maybe it would be good to introduce a Span type e.g.
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.
Though span would be a range of locations and we only have one, so it should be rather Location instead of Span.