Skip to content
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

Add positional information to error messages #209

Closed
wants to merge 3 commits into from

Conversation

halvnykterist
Copy link

No description provided.

@halvnykterist
Copy link
Author

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

Copy link
Collaborator

@kvark kvark left a comment

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

@@ -126,21 +133,27 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
V: Visitor<'de>,
{
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
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
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.

src/de/error.rs Outdated
} else {
write!(f, "{}", s)
}
}
Error::Parser(_, pos) => write!(f, "{}: {}", pos, self),
Copy link
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

@@ -61,15 +61,21 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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
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

@@ -126,21 +133,27 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
V: Visitor<'de>,
{
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
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.

@@ -39,6 +39,13 @@ impl<'de> Deserializer<'de> {
pub fn remainder(&self) -> Cow<'_, str> {
String::from_utf8_lossy(&self.bytes.bytes())
}

fn fix_position(&self, e: Error) -> Error {
Copy link
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
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

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