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

Improve backtrace locations on error #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yujinakayama
Copy link

This change improves backtrace locations of code executed with eval.

Before:

rake aborted!
ActiveRecord::RecordInvalid: Permission denied
(eval):5:in `edit_item'
(eval):47:in `block (3 levels) in run_file'
(eval):28:in `block (2 levels) in run_file'
/home/me/project/lib/tasks/db/reset.rake:10:in `block (3 levels) in <top (required)>'

After:

rake aborted!
ActiveRecord::RecordInvalid: Permission denied
/home/me/project/db/fixtures/development/00_foo.rb:5:in `do_something'
/home/me/project/db/fixtures/development/10_bar.rb:47:in `block (3 levels) in run_file'
/home/me/project/db/fixtures/development/10_bar.rb:28:in `block (2 levels) in run_file'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:48:in `eval'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:48:in `block (2 levels) in run_file'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:60:in `block in open'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:59:in `open'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:59:in `open'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:36:in `block in run_file'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:35:in `run_file'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:26:in `block in run'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:25:in `each'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:25:in `run'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu.rb:29:in `seed'
/opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/tasks/seed_fu.rake:36:in `block (2 levels) in <top (required)>'
/home/me/project/lib/tasks/db/reset_all.rake:10:in `block (3 levels) in <top (required)>'

else
chunked_ruby << line
end
end
eval(chunked_ruby) unless chunked_ruby == ''
eval(chunked_ruby, binding, filename, line_number) unless chunked_ruby == ''
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does eval automatically send the caller's binding? If not it might be best to to pass nil for binding.

Also if you do file.lineno you shouldn't need to track line_number as you do above.

Before:

    rake aborted!
    ActiveRecord::RecordInvalid: Permission denied
    (eval):5:in `edit_item'
    (eval):47:in `block (3 levels) in run_file'
    (eval):28:in `block (2 levels) in run_file'
    /home/me/project/lib/tasks/db/reset.rake:10:in `block (3 levels) in <top (required)>'

After:

    rake aborted!
    ActiveRecord::RecordInvalid: Permission denied
    /home/me/project/db/fixtures/development/00_foo.rb:5:in `do_something'
    /home/me/project/db/fixtures/development/10_bar.rb:47:in `block (3 levels) in run_file'
    /home/me/project/db/fixtures/development/10_bar.rb:28:in `block (2 levels) in run_file'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:48:in `eval'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:48:in `block (2 levels) in run_file'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:60:in `block in open'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:59:in `open'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:59:in `open'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:36:in `block in run_file'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:35:in `run_file'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:26:in `block in run'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:25:in `each'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu/runner.rb:25:in `run'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/seed-fu.rb:29:in `seed'
    /opt/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/seed-fu-2.3.4/lib/tasks/seed_fu.rake:36:in `block (2 levels) in <top (required)>'
    /home/me/project/lib/tasks/db/reset_all.rake:10:in `block (3 levels) in <top (required)>'
@yujinakayama yujinakayama force-pushed the improve-eval-backtrace-location branch from d949d83 to dad425d Compare May 19, 2015 02:46
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

Successfully merging this pull request may close these issues.

2 participants