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 #69

Open
lcowell opened this issue Mar 19, 2015 · 18 comments
Open

Encoding::UndefinedConversionError #69

lcowell opened this issue Mar 19, 2015 · 18 comments

Comments

@lcowell
Copy link

lcowell commented Mar 19, 2015

When I paste "ñ" (with quotes) in to the console with pry-rails (0.3.3) enabled I will get an Encoding::UndefinedConversionError error.

$ bundle exec rails console
main:0>"��"
/Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/history.rb:106:in `write': "\xC3" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/history.rb:106:in `puts'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/history.rb:106:in `save_to_file'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/history.rb:50:in `call'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/history.rb:50:in `push'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:267:in `handle_line'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `catch'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:242:in `block in eval'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `catch'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_instance.rb:241:in `eval'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:77:in `block in repl'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:67:in `loop'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:67:in `repl'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:38:in `block in start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/input_lock.rb:61:in `call'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/input_lock.rb:61:in `__with_ownership'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/input_lock.rb:79:in `with_ownership'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:38:in `start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/repl.rb:15:in `start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/pry-0.10.1/lib/pry/pry_class.rb:169:in `start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:47:in `start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:8:in `start'
    from /Users/lukec/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-3.2.21/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'

If I disable pry-rails in my Gemfile I get the expected output.

$ bundle exec rails console
Loading development environment (Rails 3.2.21)
irb(main):001:0> "ñ"
=> "ñ"

I'd love to get to the bottom of this, so please let me know if there's any additional information I can provide.

@momolog
Copy link

momolog commented Apr 21, 2015

Got this, too. Looks like a bug to me.

@redbar0n
Copy link

+1

› rails c
Loading development environment (Rails 4.1.10)
>> "ø"
=> "ø"
>> exit
/Users/Magne/.rvm/scripts/irbrc.rb:33:in `write': "\xC3" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
    from /Users/Magne/.rvm/scripts/irbrc.rb:33:in `puts'
    from /Users/Magne/.rvm/scripts/irbrc.rb:33:in `block (2 levels) in <top (required)>'
    from /Users/Magne/.rvm/scripts/irbrc.rb:33:in `open'
    from /Users/Magne/.rvm/scripts/irbrc.rb:33:in `block in <top (required)>'
/Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb/ext/save-history.rb:115:in `write': "\xC3" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb/ext/save-history.rb:115:in `puts'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb/ext/save-history.rb:115:in `block in save_history'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/open-uri.rb:36:in `open'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/open-uri.rb:36:in `open'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb/ext/save-history.rb:113:in `save_history'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb/ext/save-history.rb:79:in `block in extended'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb.rb:407:in `call'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb.rb:407:in `block in irb_at_exit'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb.rb:407:in `each'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb.rb:407:in `irb_at_exit'
    from /Users/Magne/.rvm/rubies/ruby-2.0.0-head/lib/ruby/2.0.0/irb.rb:400:in `start'
    from /Users/Magne/.rvm/gems/ruby-2.0.0-head@bloggery/gems/railties-4.1.10/lib/rails/commands/console.rb:90:in `start'
    from /Users/Magne/.rvm/gems/ruby-2.0.0-head@bloggery/gems/railties-4.1.10/lib/rails/commands/console.rb:9:in `start'
    from /Users/Magne/.rvm/gems/ruby-2.0.0-head@bloggery/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/Magne/.rvm/gems/ruby-2.0.0-head@bloggery/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/Magne/.rvm/gems/ruby-2.0.0-head@bloggery/gems/railties-4.1.10/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

@redbar0n
Copy link

Some other guy also documented the problem: https://gist.github.com/atton-/5facfe29cf251ef9323f

@pgolm
Copy link

pgolm commented Sep 23, 2015

👍

@rubyconvict
Copy link

pry/pry#1429 (comment)

definitely an issue with pry-rails

@rf-
Copy link
Member

rf- commented Oct 15, 2015

Could someone try running the Rails console without pry-rails, opening Pry by typing binding.pry into that Rails console session, and then reproing?

@rubyconvict
Copy link

Sorry, pry-rails is innocent, it's pry vs. rb-readline war.

1.9.3-p429 :002 > 'Ą'
 => "Ą" 
1.9.3-p429 :003 > binding.pry
[1] pry(main)> '��'
Encoding::UndefinedConversionError: "\xC4" from ASCII-8BIT to UTF-8
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/history.rb:106:in `write'
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/history.rb:106:in `puts'
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/history.rb:106:in `save_to_file'
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/history.rb:50:in `call'
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/history.rb:50:in `push'
    from /.../vendor/bundle/ruby/1.9.1/gems/pry-0.10.2/lib/pry/pry_instance.rb:267:in `handle_line'

@yoonsy
Copy link

yoonsy commented Nov 14, 2015

+1

2 similar comments
@mgrachev
Copy link

+1

@milesbissky
Copy link

+1

@lingceng
Copy link

Just remove the 'rb-readline' gem if you are on a linux like system.
This may be the current solution for this problem.

@lcowell
Copy link
Author

lcowell commented Jan 15, 2016

Removing rb-readline solved the issue for me.

@poc7667
Copy link

poc7667 commented May 5, 2016

However, if you remove rb-readline, we won't be able to type non-ascii character on the console

@jsnick
Copy link

jsnick commented Jul 5, 2016

I've solved this.
refer to pry/pry#230420454

@chunlea
Copy link

chunlea commented Feb 13, 2017

http://altarf.net/computer/rails/3222

add ~/.pryrc with content

Pry.config.history.should_save = false

and it works for me.

@rutgerg
Copy link

rutgerg commented Aug 24, 2017

+1

@Envek
Copy link

Envek commented Mar 21, 2019

Had same error on Linux in Docker image. Problem was in system locale settings (it was set to POSIX).

Fixed by setting locale to Unicode-enabled one:

FROM ruby:2.6.2
RUN apt-get update && apt-get install -y locales && update-locale LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

In your local system check output of locale command and add export LANG=C.UTF-8 LC_ALL=C.UTF-8 to your ~/.bashrc or ~/.zshrc if necessary

@Overload119
Copy link

I was able to "fix" this by adding this line in:

/Users/<username>/.rvm/gems/ruby-2.7.5/gems/pry-0.13.1/lib/pry/history.rb

def save_to_file(line)
  history_file.puts line.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') if history_file
end

Of course the issue is still there, so I opened an issue in RbReadline (see ConnorAtherton/rb-readline#163)

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