You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thread#raise is incorrectly written as def self?.raise when it should just be def raise
Big issues
More fundamentally, the method signature for Kernel/Thread/Fiber#raise is flawed, even on the official documentation. I am unsure if the current (Ruby 3.2.2) behavior is the intended one, or if the documentation is the intended one.
To my surprise, raise very interesting & complex behavior. Specifically, these are the rules I found for raise on Fiber, and Thread via experimentation (the official documentation is also not quite correct unfortunately). They may not be the only rules though.
def raise: () -> nil
| (String message) -> nil
| (Exception ex) -> nil# (edit 5) change from Exception class to Exception instance
| (_Exception ex) -> nil
| (_Exception ex, _ToS message) -> nil# (1) change from String to _ToS
| (_Exception ex, _ToS message, String backtrace) -> nil# (2) change from Array[String] to String
| (_Exception ex, _ToS message, Array[String] backtrace) -> nil# (3) change from String to _ToS
| (_Exception, **kwargs) -> nil# (4) new rule
For Kernel, the rules are the same except it also accepts an optional keyword argument ?cause: Exception at every rule variant. Note that cause: is not_Exception but Exception - _Exception is a class interface, Exception is an instance of that interface.
Here are the explanations behind each change
Any object that can be to_s will be accepted as a valid message
If only one String argument is provided for backtrace, it will treat it like an array of one element
Same as 1
All keyword arguments (except :cause in Kernel) will be converted to a Hash, stringified, then used as the message
I do not know if #raise was intended to have such complicated behavior and the docs were not updated or if this is a implementation bug. The inconsistent behavior between message and backtrace and the implicit Hashification of kwargs leads me to believe that this is a bug. If a core committer can confirm this is not intentional, I would be happy to submit an issue to the bug tracker. There perhaps we can have a more productive conversation about whether to fix this or keep it as is an update the docs.
EDIT: Just found another possible signature (5)
The text was updated successfully, but these errors were encountered:
Small issues
Thread#raise is incorrectly written as
def self?.raise
when it should just bedef raise
Big issues
More fundamentally, the method signature for Kernel/Thread/Fiber#raise is flawed, even on the official documentation. I am unsure if the current (Ruby 3.2.2) behavior is the intended one, or if the documentation is the intended one.
To my surprise, raise very interesting & complex behavior. Specifically, these are the rules I found for raise on Fiber, and Thread via experimentation (the official documentation is also not quite correct unfortunately). They may not be the only rules though.
For Kernel, the rules are the same except it also accepts an optional keyword argument
?cause: Exception
at every rule variant. Note thatcause:
is not_Exception
butException
-_Exception
is a class interface,Exception
is an instance of that interface.Here are the explanations behind each change
:cause
in Kernel) will be converted to a Hash, stringified, then used as the messageI do not know if
#raise
was intended to have such complicated behavior and the docs were not updated or if this is a implementation bug. The inconsistent behavior betweenmessage
andbacktrace
and the implicit Hashification of kwargs leads me to believe that this is a bug. If a core committer can confirm this is not intentional, I would be happy to submit an issue to the bug tracker. There perhaps we can have a more productive conversation about whether to fix this or keep it as is an update the docs.EDIT: Just found another possible signature (5)
The text was updated successfully, but these errors were encountered: