-
Notifications
You must be signed in to change notification settings - Fork 162
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?
Conversation
Skgland
left a comment
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.
src/machine/lib_machine/mod.rs
Outdated
| } | ||
|
|
||
| /// Runs query after checking parse errors. | ||
| pub fn run_query_safe( |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
I was wondering about the same thing but decided to go with gut feeling. It's not a difficult change :)
src/machine/lib_machine/mod.rs
Outdated
| @@ -591,7 +607,10 @@ impl Machine { | |||
| let term = parser | |||
| .read_term(&op_dir, Tokens::Default) | |||
| .expect("Failed to parse query"); | |||
| self.run_query_impl(term) | |||
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| /// Enum for parsing errors | ||
| #[allow(dead_code)] | ||
| #[derive(Debug)] | ||
| pub enum ParserError { |
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.
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.
struct Span {
line: usize,
column: usize
}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.
| /// Unexpected character found. | ||
| UnexpectedChar(char, usize, usize), | ||
| // UnexpectedEOF, | ||
| /// UTF8 error found. |
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.
These additional comments seem to mostly repeat the types? I would suggest leaving this out.
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.
Note that the missing_docs lint is set to deny so either this documentation or an explicit override i.e. #[allow(missing_docs)] on the enum is required now that this type is reachable.
Line 3 in 453a88f
| #![deny(missing_docs)] |
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.
Ah OK, thank you, I was already wondering why this is suddenly part of the PR.
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.
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.
|
Just to check in, is there anything that should still be done on this PR? From what I understand there are comments, but I'm not sure if they should be implemented or not. |
I think leaving the documentation as-is is fine as it can be changed at any point. The following isn't really directed at this PR but more a collection of my thought of what I think would be good to change about the
|
run_queryintorun_queryandrun_query_impl(shared logic)run_query_safethat returnsQueryStateorparser::ast::ParserErrorParserErrorin libParserErrorand associated methods