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
Prevent malformed exception messages from exiting RSpec #2761
Conversation
65b32d1
to
d936026
Compare
0405330
to
c79d1f2
Compare
c79d1f2
to
468c989
Compare
3276f34
to
39f7ffc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks Jon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
# rubocop:disable Lint/RescueException | ||
def exception_message_string(exception) | ||
exception.message.to_s | ||
rescue Exception => other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NoMemoryError.superclass # => Exception
maybe rescue from StandardError
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No the point is to avoid crashing due to calling this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean we can't recover from a NoMemoryError
by swallowing it.
On the other hand, SystemStackError
is also an Exception
, and it may be caused by an incorrectly implemented message
. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we might be able to because we're not necessarily assigning memory, but Ruby doesn't have a system level of exception unfortunately
Prevent malformed exception messages from exiting RSpec
Prevent malformed exception messages from exiting RSpec
…e-to_s-loop Prevent malformed exception messages from exiting RSpec --- This commit was imported from rspec/rspec-core@e6455b9.
When an exception message raises when to_s is called, particularly the loop style presented by #2753, RSpec will hard loop as it tries and fails to produce a valid string for the exception, this detects and prevent this from happening and produces a reasonable stand in explanation, but its not advisable (or possible in the case of the spec example) to introspect the error itself.
Fixes #2753.