Library: add run_query_safe exposing parsing errors#3236
Library: add run_query_safe exposing parsing errors#3236exlee wants to merge 1 commit intomthom:masterfrom
Conversation
Skgland
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
These additional comments seem to mostly repeat the types? I would suggest leaving this out.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Ah OK, thank you, I was already wondering why this is suddenly part of the PR.
There was a problem hiding this comment.
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