Skip to content

Add positional information to error messages#209

Closed
halvnykterist wants to merge 3 commits into
ron-rs:masterfrom
halvnykterist:master
Closed

Add positional information to error messages#209
halvnykterist wants to merge 3 commits into
ron-rs:masterfrom
halvnykterist:master

Conversation

@halvnykterist

Copy link
Copy Markdown

No description provided.

@halvnykterist

Copy link
Copy Markdown
Author

This seems to cause a stack overflow under some circumstances so that's probably bad

@kvark kvark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!
Have some questions

Comment thread src/de/mod.rs
{
if self.bytes.consume_ident("true") {
return visitor.visit_bool(true);
return visitor.visit_bool(true).map_err(|e| self.fix_position(e));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all these cases just don't return positional errors to begin with?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the errors are generated by fn custom<T: fmt::Display>(msg: T) -> Self on Error in error.rs. In serde's json deserializer ( https://github.com/serde-rs/json/blob/master/src/error.rs#L380 ) they've already got the line number and column built into the message, somehow, but I have a hard time following the path.

Comment thread src/de/error.rs Outdated
write!(f, "{}", s)
}
}
Error::Parser(_, pos) => write!(f, "{}: {}", pos, self),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is causing a loop and overflow, somehow. I don't understand how it was working before since I can't find any kind of implementation that's actually doing display for ParseError

Comment thread src/de/error.rs
match *self {
Error::IoError(ref s) => write!(f, "{}", s),
Error::Message(ref s) => write!(f, "{}", s),
Error::Parser(_, pos) => write!(f, "{}: {}", pos, self),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was causing a stack overflow and I don't understand how it was working before

Comment thread src/de/mod.rs
{
if self.bytes.consume_ident("true") {
return visitor.visit_bool(true);
return visitor.visit_bool(true).map_err(|e| self.fix_position(e));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the errors are generated by fn custom<T: fmt::Display>(msg: T) -> Self on Error in error.rs. In serde's json deserializer ( https://github.com/serde-rs/json/blob/master/src/error.rs#L380 ) they've already got the line number and column built into the message, somehow, but I have a hard time following the path.

Comment thread src/de/mod.rs
String::from_utf8_lossy(&self.bytes.bytes())
}

fn fix_position(&self, e: Error) -> Error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's just make it so the input error type and the output error type are different. This will still require us to call it, but there will be no way to miss a fix step.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds smart, I'll give that a try

@github-actions

Copy link
Copy Markdown

Issue has had no activity in the last 60 days and is going to be closed in 7 days if no further activity occurs

@github-actions github-actions Bot added the stale label Nov 18, 2021
@github-actions github-actions Bot closed this Nov 26, 2021
juntyr added a commit to juntyr/ron that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants