JSON::GeneratorError expose invalid object#712
Merged
byroot merged 1 commit intoruby:masterfrom Nov 25, 2024
Merged
Conversation
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é <[email protected]>
mperham
reviewed
Nov 26, 2024
| if @invalid_object.nil? | ||
| super | ||
| else | ||
| "#{super}\nInvalid object: #{@invalid_object.inspect}" |
Contributor
There was a problem hiding this comment.
The only quibble I've run into when pulling this into Sidekiq is the newline here. It's injecting formatting into the message, typically if I want to log an error message I don't expect it to take multiple lines in the log output. WDYT?
Contributor
There was a problem hiding this comment.
Of course we expect newlines with backtraces... Could exceptions support a hash of context values to be logged with the error, where invalid_object would already be there? This is pretty standard stuff for structured logging, e.g. Golang.
rescue JSON::GeneratorError => ex
logger.info { ex.with_context(some: value, another: value).detailed_message }I guess the bigger question would be if ruby-core wants to move toward more formalized structured logging, by providing these types of APIs.
This was referenced Mar 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: #710
Makes it easier to debug why a given tree of objects can't be dumped as JSON.