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

Prevent malformed exception messages from exiting RSpec #2761

Merged
merged 1 commit into from Sep 4, 2020

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Sep 3, 2020

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.

JonRowe added a commit that referenced this pull request Sep 3, 2020
JonRowe added a commit that referenced this pull request Sep 3, 2020
JonRowe added a commit that referenced this pull request Sep 3, 2020
Copy link
Member

@benoittgt benoittgt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks Jon.

@JonRowe JonRowe merged commit 5b685b3 into main Sep 4, 2020
@JonRowe JonRowe deleted the fix-message-to_s-loop branch September 4, 2020 12:05
Copy link
Member

@pirj pirj left a 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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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. 👍

Copy link
Member Author

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

JonRowe added a commit that referenced this pull request Sep 30, 2020
Prevent malformed exception messages from exiting RSpec
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Prevent malformed exception messages from exiting RSpec
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…e-to_s-loop

Prevent malformed exception messages from exiting RSpec

---
This commit was imported from rspec/rspec-core@e6455b9.
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.

RSpec crashes due to bad message of exception
3 participants