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::UndefinedConversionError ("\xE2" from ASCII-8BIT to UTF-8) #198

Closed
tae8838 opened this issue Jan 15, 2021 · 4 comments
Closed

Comments

@tae8838
Copy link

tae8838 commented Jan 15, 2021

I am trying to enqueue a mailer job with attached pdf and I got this error. It was working when I was using delayed_job. We are trying to switch to good_job because it supports jruby.

I ran wtf? on my pry and got this trace:

Exception: Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8
--
0: org/jruby/RubyString.java:6225:in `encode'
1: json/ext/GeneratorMethods.java:105:in `to_json'
2: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activesupport-6.1.1/lib/active_support/core_ext/object/json.rb:40:in `to_json'
3: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activesupport-6.1.1/lib/active_support/json/encoding.rb:57:in `to_json'
4: json/ext/GeneratorState.java:209:in `generate'
5: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/stdlib/json/common.rb:224:in `generate'
6: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activesupport-6.1.1/lib/active_support/json/encoding.rb:110:in `stringify'
7: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activesupport-6.1.1/lib/active_support/json/encoding.rb:35:in `encode'
8: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activesupport-6.1.1/lib/active_support/json/encoding.rb:22:in `encode'
9: /Users/tae/.rbenv/versions/jruby-9.2.11.1/lib/ruby/gems/shared/gems/activerecord-6.1.1/lib/active_record/type/json.rb:18:in `serialize'

I'm still looking into this issue. Will update if I figure anything else out.
Thank you!

@bensheldon
Copy link
Owner

Thanks for trying out GoodJob!

It looks like maybe when the ActiveJob/ActionMailer params are serialized into JSON to be stored in the database for GoodJob, there is an encoding issue.

Could you share the code you're invoking that triggers this error? I'd like to understand how the PDF is attached.

@slimdave
Copy link

FWIW I have seen similar errors when reading from files (actually when using Paperclip.io_adaptors.for(attachment).read) and I think the issue is an assumption that the data is ASCII, which was fixed by appending force_encoding("UTF-8") to the method chain. Hope this helps.

@headius
Copy link

headius commented Jan 15, 2021

Make sure you are running latest JRuby and the json gem... I think there have been some encoding fixes over the past year or so.

@tae8838
Copy link
Author

tae8838 commented Jan 19, 2021

Thanks for the comments. I worked around this by using the object in the params and query for the file in the mailer.

Not sure if anyone else wants to look into this but the code I used was something like this:

files = PurchaseOrder.where(active: true).map { |po| { content: po.po_file.blob.download, name: "#{po.purchase_order_number}.pdf" } }

MyMailer.send_email(to_emails, to_emails, files).deliver_later

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

4 participants