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

Fix exception(backtrace=nil) prints nothing #782

Merged
merged 1 commit into from Nov 25, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Nov 23, 2023

When an exception that has backtrace=nil is raised, IRB prints nothing.

irb(main):001> raise StandardError.new('error').tap{def _1.backtrace()=nil}
irb(main):002> raise _
irb(main):003> _
=> #<StandardError: error>
irb(main):004> 

I removed if exc.backtrace condition. files?w=1
Any error on printing error with backtrace will be rescued after #780.

The original test properly ensures stderr to be empty, but it was not properly testing stdout.

assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
  e = Exception.new("foo")
  puts e.inspect
  def e.backtrace; nil; end
  raise e
IRB
e = Exception.new("foo")  # prints "=> #<Exception: foo>" that makes test pass
puts e.inspect            # prints "#<Exception: foo>" and "nil" that also makes test pass
def e.backtrace; nil; end # prints "=> :backtrace"
raise e                   # should print some error message and this should be tested but it doesn't

@tompng tompng force-pushed the print_backtraceless_exception branch from f2e4da1 to 7a63461 Compare November 23, 2023 14:27
@tompng tompng force-pushed the print_backtraceless_exception branch from 7a63461 to df42a6b Compare November 23, 2023 18:18
@tompng tompng marked this pull request as ready for review November 23, 2023 18:20
lib/irb.rb Show resolved Hide resolved
@st0012 st0012 added the bug Something isn't working label Nov 24, 2023
@tompng tompng merged commit fa9ecf9 into ruby:master Nov 25, 2023
22 of 24 checks passed
@tompng tompng deleted the print_backtraceless_exception branch November 25, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

None yet

2 participants