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

Better error debugging for generation #710

Closed
mperham opened this issue Nov 24, 2024 · 4 comments · Fixed by #712
Closed

Better error debugging for generation #710

mperham opened this issue Nov 24, 2024 · 4 comments · Fixed by #712

Comments

@mperham
Copy link
Contributor

mperham commented Nov 24, 2024

I'm trying to figure out why JSON is blowing up when generating the JSON for a big ole Hash of stuff. It raises a GeneratorError, but with no context so I can't easily tell where my bad data is. The line in question is here:

rb_raise(rb_path2class("JSON::GeneratorError"), "source sequence is illegal/malformed utf-8");

I would suggest this error include the relevant object at fault. Something like:

class JSON::GeneratorError
  attr_reader :invalid_element
end
@byroot
Copy link
Member

byroot commented Nov 24, 2024

Makes sense. Wouldn't be too hard to implement.

byroot added a commit to byroot/json that referenced this issue Nov 25, 2024
Fix: ruby#710

Makes it easier to debug why a given tree of objects can't
be dumped as JSON.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
@mperham
Copy link
Contributor Author

mperham commented Nov 25, 2024

Thank you, it worked great.

Should it emit the invalid object as part of message? That's extremely useful context that most people won't know exists. Is the attribute in the RDoc?

@byroot
Copy link
Member

byroot commented Nov 25, 2024

The object may be huge, that's why it's included in detailed_message and not just message, to avoid things like: https://bugs.ruby-lang.org/issues/18285

@mperham
Copy link
Contributor Author

mperham commented Nov 25, 2024

TIL about #detailed_message! I think I could roll this into Sidekiq's debugging output: turn on debugging => get detailed_message logged which will solve my need.

https://docs.ruby-lang.org/en/master/Exception.html#method-i-detailed_message

hsbt pushed a commit to hsbt/ruby that referenced this issue Nov 26, 2024
Fix: ruby/json#710

Makes it easier to debug why a given tree of objects can't
be dumped as JSON.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
hsbt pushed a commit to ruby/ruby that referenced this issue Nov 26, 2024
Fix: ruby/json#710

Makes it easier to debug why a given tree of objects can't
be dumped as JSON.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants