Skip to content

Commit

Permalink
- Add DEBUG=1 tip on general exception
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Jan 26, 2023
1 parent 0037e92 commit 3fab8f5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/runfile/entrypoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ def run!
say! 'm`Goodbye`', replace: true
1
rescue => e
puts e.backtrace.reverse if ENV['DEBUG']
if ENV['DEBUG']
say! e.backtrace.reverse.join("\n")
say! '---'
end
origin = e.backtrace_locations.first
location = "#{origin.path}:#{origin.lineno}"
say! "rib` #{e.class} ` in nu`#{location}`"
say! e.message
say! "\nPrefix with nu`DEBUG=1` for full backtrace" unless ENV['DEBUG']
1
end

Expand Down
4 changes: 2 additions & 2 deletions lib/runfile/userfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ def find_action(args)

def run_local(argv)
exit_code = nil

Runner.run docopt, argv: argv, version: version do |args|
action = find_action(args)
raise ActionNotFound, 'Cannot find action. Is it properly defined?' unless action

exit_code = action.run args
end

exit_code if exit_code.is_a? Integer
end

Expand Down
2 changes: 2 additions & 0 deletions spec/approvals/bin/action-error
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
 ZeroDivisionError  in runfile:2
divided by 0

Prefix with DEBUG=1 for full backtrace
2 changes: 2 additions & 0 deletions spec/approvals/bin/syntax-error
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
 NameError  in runfile:1
undefined local variable or method `nicely' for #<Runfile::Userfile name=nil, path="runfile", context={}>

Prefix with DEBUG=1 for full backtrace
7 changes: 7 additions & 0 deletions spec/runfile/entrypoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
expect { subject.run! }.to output(/some error/).to_stderr
end

it 'exits displays backtrace on exceptions when DEBUG=1' do
ENV['DEBUG'] = '1'
allow(subject).to receive(:run).and_raise(StandardError, 'some error')
expect { subject.run! }.to output(%r{lib/rspec}).to_stderr
ENV['DEBUG'] = nil
end

context 'when the masterfile action ends with an integer value' do
let(:argv) { %w[] }

Expand Down

0 comments on commit 3fab8f5

Please sign in to comment.