Skip to content

Conversation

@cboos
Copy link
Contributor

@cboos cboos commented Dec 29, 2021

In ErrorHighlight::CoreExt#to_s, the backtrace_locations is checked before use, but that check doesn't cover all the cases.

If you happen to call directly rb_funcallv from a C program in an embedded Ruby scenario and an exception is raised, then the backtrace_locations will be an empty Array, not nil. In such an application, my error reporting code calls to_s on the rb_errinfo() value, and with Ruby 3.1 this results in a TypeError: wrong argument type nil (expected method) as the ErrorHighlight::CoreExt#to_s method uses a loc that is now nil.

I believe the correct thing to do here is to return msg as well.

The test fails with the following error:

Error: test_simulate_funcallv_from_embedded_ruby(ErrorHighlightTest): TypeError: wrong argument type nil (expected method)
When we have no backtrace locations, we can't have the highlight,
so just return the message.
Copy link

@Didthat Didthat left a comment

Choose a reason for hiding this comment

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

Duplicate of #
Duplicate of #

@cboos
Copy link
Contributor Author

cboos commented Jan 3, 2022

Duplicate of # Duplicate of #

Spam?

@hsbt
Copy link
Member

hsbt commented Jan 3, 2022

Spam?

Yes. We couldn't delete that.

GitHub must fix this behavior or prevent to post as spam.

@mame
Copy link
Member

mame commented Jan 4, 2022

@cboos Thank you for your pull request! It looks reasonable. I'll merge it soon.

@mame mame merged commit 9f5c639 into ruby:master Jan 4, 2022
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.

4 participants