Guard导致“错误:无法修改字符串;暂时锁定”

时间:2013-10-21 14:13:56

标签: rspec guard rbenv

当使用guard-rspec在Rails 4项目中运行guard时,我在vim中打开/关闭文件时偶尔会看到以下错误。我试过升级/降级后卫,guard-rspec,pry和其他没有运气的库。

  • ruby​​ 2.0.0p247(2013-06-27修订版41674)[x86_64-linux]
  • Bundler版本1.3.5
  • Guard version 2.1.1

下面是我看到的每一次测试运行的堆栈跟踪:

Error: can't modify string; temporarily locked
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:624:in `readline'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:624:in `block in readline'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:564:in `handle_read_errors'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:609:in `readline'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:384:in `retrieve_line'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:301:in `block in r'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:298:in `loop'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:298:in `r'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:276:in `re'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:254:in `rep'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:234:in `block (3 levels) in repl'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:232:in `loop'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:232:in `block (2 levels) in repl'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:231:in `catch'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:231:in `block in repl'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:230:in `catch'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_instance.rb:230:in `repl'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/pry-0.9.12.2/lib/pry/pry_class.rb:170:in `start'
/home/charles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/guard-2.1.1/lib/guard/interactor.rb:133:in `block in start'
[1] Specs guard(main)>

3 个答案:

答案 0 :(得分:16)

rb-readline gem添加到我的Gemfile似乎解决了这个问题。

gem "rb-readline", "~> 0.5.0"

我的猜测是Ruby 2.0.0-p247的rbenv编译版本有readline问题,这解释了pry_instance.rb:624:in 'readline'中出现错误的原因。 rb-readline项目是readline库的纯ruby实现,似乎可以缓解这个问题。

可能有更好的解决方案涉及重新编译ruby,但我还没有找到它。

答案 1 :(得分:3)

在Ruby 2.0.0和1.9.3中确实似乎是一个错误。见https://bugs.ruby-lang.org/issues/8669

它在版本42216中向后移植到Ruby 2.0.0。

答案 2 :(得分:0)

你正在使用Sublime Text 3吗?如果是的话,你绝对应该check this out

TLDR:设置"atomic_save": false