ruby / error_highlight

The gem enhances Exception#message by adding a short explanation where the exception is raised
MIT License
150 stars 23 forks source link

Fix type error on empty backtrace locations #18

Closed cboos closed 2 years ago

cboos commented 2 years ago

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.

cboos commented 2 years ago

Duplicate of # Duplicate of #

Spam?

hsbt commented 2 years ago

Spam?

Yes. We couldn't delete that.

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

mame commented 2 years ago

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