Skip to content
This repository

Ruby 2.0.0 + pry - error when using up arrow to replay previous command #863

Closed
andrewbaldwin opened this Issue · 19 comments

7 participants

andrewbaldwin Ryan Fitzgerald mathew Kyrylo Silin yubrew Chris markson
andrewbaldwin

This error applies to 2.0.0 only - works OK with 1.9.2 and 1.9.3

I've tried using "rvm pkg readline" and reinstalling rubies but it made no difference.

Appears to be an effect of Ruby reading the up arrow escape sequence as UTF characters.

Fundamental question: is pry supported on 2.0.0 ? [or is this a readline issue?] Is there a orkaround to turn off UTF character handling?

example snapshot shown below:

andrew@Hex:~$ rvm use 2.0.0@rails
Using /home/andrew/.rvm/gems/ruby-2.0.0-rc2 with gemset rails
andrew@Hex:~$ pry
Can't find Pry.config.theme definition in your ~/.pryrc.
Using "pry-classic" theme now.
[1] pry(main)> a="123"
=> "123"

<<<<< UP-Arrow key pressed here - would expect to see ' a="123" ' again >>>>>

[2] pry(main)> Error: invalid byte sequence in UTF-8
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in block in _rl_dispatch_subseq'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in
each'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in detect'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in
_rl_dispatch_subseq'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4271:in _rl_dispatch_subseq'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4251:in
_rl_dispatch'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4669:in readline_internal_charloop'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4743:in
readline_internal'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/rbreadline.rb:4765:in readline'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/rb-readline-0.4.2/lib/readline.rb:40:in
readline'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:624:in block in readline'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:564:in
handle_read_errors'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:609:in readline'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:384:in
retrieve_line'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:301:in block in r'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:298:in
loop'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:298:in r'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:276:in
re'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:254:in rep'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:234:in
block (3 levels) in repl'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:232:in loop'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:232:in
block (2 levels) in repl'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:231:in catch'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:231:in
block in repl'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:230:in catch'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_instance.rb:230:in
repl'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/pry_class.rb:170:in start'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/cli.rb:201:in
block in '
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/cli.rb:70:in call'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/cli.rb:70:in
block in parse_options'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/cli.rb:70:in each'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/lib/pry/cli.rb:70:in
parse_options'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/gems/pry-0.9.12/bin/pry:16:in <top (required)>'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/bin/pry:19:in
load'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/bin/pry:19:in <main>'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/bin/ruby_noexec_wrapper:14:in
eval'
/home/andrew/.rvm/gems/ruby-2.0.0-rc2@rails/bin/ruby_noexec_wrapper:14:in `'
[2] pry(main)> A

<<<<< guessing this A is the end of the up arrow escape sequence >>>>>

Ryan Fitzgerald
Owner

This is probably an issue with rb-readline, which replaces the real Readline. Try removing it (and coolline if you're using it) from your Gemfile.

andrewbaldwin

Tried this (having previously included the rvm pkg readline and recompiling - see previous note) but it now stops pry (and irb) from working -- see snippet below.

If necessary I'll remove all rubies entirely and start afresh [though I'd prefer not to as this would be time consuming] -- for the moment though I'm puzzled as to how to track down exactly where the problem lies.

~~~~~~~~~~ snippet ~~~~~~~~~~~

rvm use 2.0.0@rails
Using /home/andrew/.rvm/gems/ruby-2.0.0-rc2 with gemset rails
andrew@Hex:~$ gem uninstall rb-readline
Successfully uninstalled rb-readline-0.4.2
andrew@Hex:~$ pry
You're running a version of ruby with no Readline support
Please gem install rb-readline or recompile ruby --with-readline.

andrewbaldwin

closed in error -- my fault !!

andrewbaldwin

Tried:
uninstalling rb-readline
rvm pkg readline
doing a forced rvm reinstall of 2.0.0 with the --readline-dir flag as indicated on the rvm web pages

still no joy :-(

andrewbaldwin

Tried reinstall with just --readline flag (as per error message Please gem install rb-readline or recompile ruby --with-readline)

This didn't work - just got same error message; reinstalling with the --readline-dir flag

For the time being it looks like I'll be sticking with 1.9.3

mathew
lpar commented

Works fine for me.

Ruby 2.0.0p0, Kubuntu 12.04, LC_ALL=en_DK.UTF-8, no rb-readline installed, libreadline 6.2.

Ruby built using rbenv/ruby-build, no special flags.

andrewbaldwin

I'll give it another go -- and check my version of libreadline.

Glad it worked for you - and thanks for the reply (gives me hope/incentive to try again)

andrewbaldwin

Tried again

Ubuntu 12.04LTS libreadline6.2 (with libreadline sym linked to it)

Installed using "rvm reinstall 2.0.0" (no flags added)

Still getting same behaviour. It's frustrating - must be some old library path hangup causing incompatible readline somewhere.

Will try a clean install of Linux, RVM & Ruby in aVM to see if that fixes it

Kyrylo Silin
Collaborator

@andrewbaldwin, great! I really appreciate your efforts to track the bug down. You're helping a lot.

andrewbaldwin

OK tried with a fresh install of Linux Mint and everything works beautifully.

So now it's down to tracking down the versions and variants of libraries etc. -- or just migrate my Ubuntu system

Not sure how much this helps, but if I do finally nail it, I'll post results here

andrewbaldwin

Slight pause as I was unwell for a few days. Now have two lists - one from my Ubuntu system with a huge amount of accumulated cruft and bloat, one from the freshly installed Mint system. It looks like everything that's on the Mint system has a corresponding file on the Ubuntu one so I'm guessing it's down to the order in which libraries are loaded and a "wrong" one has been chosen from the other in preference.

All in all it looks as if pry is fine - so apologies for making this entry in this issues list; if I do track down the offending file I'll post it here in the hope it helps someone else and then close the thread.

yubrew

I have the same problem. pry-0.9.12, ruby-2.0.0-p0, OS X 10.7.5, rvm 1.19.0.

If it's a library order problem, and a fresh install works, would deleting and reinstalling all gems could do the trick? I tried deleting and reinstalling, but still had the same problem.

mathew
lpar commented

I used pldd to dump out the linked libraries for my working irb while it was running, after verifying that up arrow worked.

# pldd 2293
2293:   /home/meta/.rbenv/versions/2.0.0-p0/bin/ruby
linux-vdso.so.1
/lib/x86_64-linux-gnu/libpthread.so.0
/lib/x86_64-linux-gnu/librt.so.1
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/libcrypt.so.1
/lib/x86_64-linux-gnu/libm.so.6
/lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/readline.so
/lib/x86_64-linux-gnu/libreadline.so.6
/lib/x86_64-linux-gnu/libtinfo.so.5

Perhaps comparing with the same output from a non-working irb on Linux will prove enlightening? The parameter to pldd is the pid of the process, and you have to run it as root.

Here's another possible variable—I have a .inputrc for readline:

% cat ~/.inputrc 
set show-all-if-ambiguous on
set completion-ignore-case on
"\e[A":history-search-backward
"\e[B":history-search-forward
$if Bash
  Space: magic-space
$endif

The history-search mappings might be the magic that makes it work for me?

yubrew

I did some more testing. It seems irb -> pry works fine. rails c -> pry has the invalid byte sequence UTF-8 error.

I think otool is the equivalent of pldd in OS X

otool -L /Users/johnyu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
/Users/johnyu/.rvm/rubies/ruby-2.0.0-p0/bin/ruby:
    /Users/johnyu/.rvm/rubies/ruby-2.0.0-p0/lib/libruby.2.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
mathew
lpar commented

OK, I threw together a quick trivial Rails 3 app, fired up the Rails local server, and triggered a binding.pry call I'd added to the controller. Arrow keys still worked. So I dumped the loaded libraries from that process too:

4201:   /home/meta/.rbenv/versions/2.0.0-p0/bin/ruby
linux-vdso.so.1
/lib/x86_64-linux-gnu/libpthread.so.0
/lib/x86_64-linux-gnu/librt.so.1
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/libcrypt.so.1
/lib/x86_64-linux-gnu/libm.so.6
/lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/pathname.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/etc.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/digest/sha1.so
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
/lib/x86_64-linux-gnu/libz.so.1
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/digest.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/socket.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/fcntl.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/openssl.so
/lib/x86_64-linux-gnu/libssl.so.1.0.0
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/stringio.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/strscan.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/psych.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/date_core.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/bigdecimal.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/readline.so
/lib/x86_64-linux-gnu/libreadline.so.6
/lib/x86_64-linux-gnu/libtinfo.so.5
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.so
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0
/lib/x86_64-linux-gnu/libnss_files.so.2
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/digest/md5.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/racc/cparse.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/json/ext/parser.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/utf_16be.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/utf_16le.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/utf_32be.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/utf_32le.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/json/ext/generator.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/zlib.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/trans/single_byte.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/enc/trans/utf_16_32.so
/home/meta/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/io/console.so
yubrew

I figured out what the problem is. rb-readline 0.4.2 is the offending gem, and has compatibility problems with ruby 2.0.0. Upgrading to rb-readline 0.5.0.pre.1 was the solution for me. Because it is not released to rubygems yet, I installed it locally.

git clone git://github.com/luislavena/rb-readline.git
cd rb-readline
rake install    #this creates the gem locally
gem uninstall rb-readline    #make sure to comment out rb-readline in your Gemfile
gem install /path/to/rb-readline.gem

luislavena/rb-readline#81

andrewbaldwin

Logged in after a few days and have caught up with the postings.

I'd like to thank you for (a) community support & investigation and (b) for posting the solution -- just tried it and it works brilliantly.

Peter Giacomo Lombardo pglombardo referenced this issue in luislavena/rb-readline
Closed

wrapping 0.5.0 release #79

Chris

At the pry prompt, using the back arrow, I am getting ^[[D. On further investigation, with the pry console I am getting the symptom marked above. I am using ruby 2.1.0. I assume this is the same problem and am posting this so people who first encounter the problem using pry in Guard will find this page.

markson

rb_readline works for me!

Christian stayhero referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.