-
Notifications
You must be signed in to change notification settings - Fork 216
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
core: Kernel.fail is able to accept keyword arguments #1567
Conversation
For compatibility, Kernel.fail (as kwnon as raise) is able to accept keyword arguments. It's not undocumented in the Ruby language documentation, but it's surely mentioned in the Ruby's spec. refs: https://github.com/ruby/ruby/blob/v3_2_0/spec/ruby/shared/kernel/raise.rb#L38-L50
@@ -844,6 +844,7 @@ module Kernel : BasicObject | |||
def self?.fail: () -> bot | |||
| (string message, ?cause: Exception?) -> bot | |||
| (_Exception exception, ?_ToS? message, ?String | Array[String] | nil backtrace, ?cause: Exception?) -> bot | |||
| (_Exception exception, ?cause: Exception?, **untyped) -> bot |
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.
| (_Exception exception, ?String | Array[String] | nil backtrace, ?cause: Exception?, **untyped) -> bot
🗑️ Withdraw this suggestion.
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.
Note: Kernel.raise
accepts keyword arguments only if no positional arguments. So it's not good to add backtrace
argument here.
irb(main):007> raise Exception, foo: 1
(irb):7:in `<main>': {:foo=>1} (Exception)
from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):008> raise Exception, '', foo: 1
(irb):8:in `set_backtrace': backtrace must be Array of String (TypeError)
from (irb):8:in `raise'
from (irb):8:in `<main>'
from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):009> raise Exception, '', [], foo: 1
(irb):9:in `raise': wrong number of arguments (given 4, expected 0..3) (ArgumentError)
from (irb):9:in `<main>'
from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):010> raise Exception, [], foo: 1
(irb):10:in `set_backtrace': backtrace must be Array of String (TypeError)
from (irb):10:in `raise'
from (irb):10:in `<main>'
from /Users/tkomiya/.dotfiles/_rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.1/exe/irb:9:in `<top (required)>'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/tkomiya/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
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.
👍
For compatibility, Kernel.fail (as kwnon as raise) is able to accept keyword arguments. It's not undocumented in the Ruby language documentation, but it's surely mentioned in the Ruby's spec.
refs: https://github.com/ruby/ruby/blob/v3_2_0/spec/ruby/shared/kernel/raise.rb#L38-L50