-
Notifications
You must be signed in to change notification settings - Fork 43
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
method_source can raise a EOFError. #11
Comments
You'll need to run this twice or three times to trigger it. |
Try changing the last line of your file to |
Adjusting require 'rubygems'
require 'method_source'
block = proc { puts "Hello, world!" }
original = block.source
File.open('/tmp/foo.txt', 'a') { |f| f.write(original) }
line = File.readlines('/tmp/foo.txt').size
buf = File.read '/tmp/foo.txt'
block = eval(buf, binding, '/tmp/foo.txt', line )
block.source |
It should be able to show the prompt source in this example, but it fails with an 90: NAV_PROMPT = [
91: proc do |_, level, pry|
92: tree = pry.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
93: "[#{pry.input_array.size}] (pry) #{tree}: #{level}> "
94: end,
95: proc do |_, level, pry|
96: tree = pry.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
97: "[#{pry.input_array.size}] (pry) #{tree}: #{level}* "
98: end,
99: ]
100:
101: # Deal with the ^D key being pressed, different behaviour in
102: # different cases:
103: # 1) In an expression - behave like `!` command (clear input buffer)
104: # 2) At top-level session - behave like `exit command (break out of repl loop)
105: # 3) In a nested session - behave like `cd ..` (pop a binding)
106: DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
107: if !eval_string.empty?
108: # clear input buffer
109: eval_string.replace("")
110: elsif _pry_.binding_stack.one?
111: # ^D at top-level breaks out of loop
112: _pry_.binding_stack.clear
113: throw(:breakout)
114: else
115: # otherwise just pops a binding
116: _pry_.binding_stack.pop
117: end
118: end
[37] (pry) unknown: 0> Pry.config.prompt.first.source_location
=> ["/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/pry-0.9.8pre4/lib/pry.rb", 91]
[38] (pry) unknown: 0> Pry.config.prompt.first.source
EOFError: end of file reached
from /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/method_source-0.7.0/lib/method_source.rb:44:in `readline'
[39] (pry) unknown: 0> |
To reproduce:
If you change the mode from
a
tow
, it works fine.It looks like method_source loops past the end of the file (
valid_expression?
never returns true).The text was updated successfully, but these errors were encountered: