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

Encoding::InvalidByteSequenceError when handling exception in safe_perform #118

Open
koenigma1 opened this issue Sep 26, 2014 · 0 comments

Comments

@koenigma1
Copy link

Summary: safe_perform! catches exceptions, and then records the exception through the failed method:
failed("The task failed because of an error: #{e}")
Eventually we attempt to dump the exception string to JSON and get this error:
Encoding::InvalidByteSequenceError: "\xC7" on US-ASCII
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 123 in encode
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 123 in escape
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 69 in escape
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 177 in encode_json
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 48 in block in encode
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 77 in check_for_circular_references
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 46 in encode
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 252 in block in encode_json
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 252 in each
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 252 in map
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 252 in encode_json
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 48 in block in encode
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 77 in check_for_circular_references
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 46 in encode
activesupport-3.2.19/lib/active_support/json/encoding.rb" line 31 in encode
activesupport-3.2.19/lib/active_support/core_ext/object/to_json.rb" line 16 in to_json
multi_json-1.3.7/lib/multi_json/adapters/json_common.rb" line 11 in dump
multi_json-1.3.7/lib/multi_json.rb" line 115 in dump
resque-1.25.2/lib/resque.rb" line 31 in encode
resque-status-d8b2bbba92ed/lib/resque/plugins/status/hash.rb" line 193 in block (2 levels) in singletonclass
resque-status-d8b2bbba92ed/lib/resque/plugins/status/hash.rb" line 41 in set
resque-status-d8b2bbba92ed/lib/resque/plugins/status.rb" line 184 in status=
resque-status-d8b2bbba92ed/lib/resque/plugins/status.rb" line 249 in set_status
resque-status-d8b2bbba92ed/lib/resque/plugins/status.rb" line 227 in failed
resque-status-d8b2bbba92ed/lib/resque/plugins/status.rb" line 173 in rescue in safe_perform!
resque-status-d8b2bbba92ed/lib/resque/plugins/status.rb" line 160 in safe_perform!

I monkey-patched a workaround for this issue, but I don't think this is good solution. Looking for a suggestion of a good way to fix this so I can create a PR.
https://github.com/quirkey/resque-status/blob/master/lib/resque/plugins/status.rb#L173
# start monkey patch
msg = "The task failed because of an error: #{e}"
encoding_options = {
:invalid => :replace, # Replace invalid byte sequences
:undef => :replace, # Replace anything not defined in ASCII
:replace => '?', # Use a ? for those replacements
:universal_newline => true # Always break lines with \n
}
msg.encode!(Encoding.find('ASCII'), encoding_options)
failed(msg)
# end monkey patch
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant