[#84867] [Ruby trunk Bug#14357] thread_safe tests suite segfaults — v.ondruch@...

Issue #14357 has been reported by vo.x (Vit Ondruch).

11 messages 2018/01/15

[#84980] [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — hsbt@...

Issue #13618 has been updated by hsbt (Hiroshi SHIBATA).

10 messages 2018/01/23
[#85012] Re: [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — Eric Wong <normalperson@...> 2018/01/23

hsbt@ruby-lang.org wrote:

[ruby-core:84683] [Ruby trunk Feature#14313] Support creating KeyError with receiver and key from Ruby

From: kou@...
Date: 2018-01-07 06:22:28 UTC
List: ruby-core #84683
Issue #14313 has been updated by kou (Kouhei Sutou).


`Kernel.#raise` expects backtrace for the 3rd argument.
If we want to extend the current `Kernel.#raise` behavior, we should create a new issue instead of discussing  in this issue.


----------------------------------------
Feature #14313: Support creating KeyError with receiver and key from Ruby
https://bugs.ruby-lang.org/issues/14313#change-69397

* Author: kou (Kouhei Sutou)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
`KeyError` has readers for error details, `receiver` and `key`. They are convenient to process `KeyError`.

We can set `receiver` and `key` to `KeyError` by `rb_key_err_new()` in C. But we can't set them in Ruby. Because `receiver` and `key` use no `@` instance variables.

How about adding `KeyError#initialize` that accepts `receiver` and `key`? Because `KeyError` is useful in pure Ruby libraries. For example, csv library uses `KeyError`: https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/csv.rb?revision=59849&view=markup#l321

```ruby
def fetch(header, *varargs)
  # ...
  raise KeyError, "key not found: #{header}"
  # ...
end
```

I want to use `KeyError` for `Hash` like objects such as `Arrow::Table` in [Red Arrow](https://github.com/red-data-tools/red-arrow/).

The attached patch adds `KeyError#initialize` that behaves as the following:

```ruby
p KeyError.new.message
# => "KeyError": No change. Keep backward compatibility.

p KeyError.new("Message").message
# => "Message": No change. Keep backward compatibility.

p KeyError.new(receiver: Object.new).receiver
# => The Object instance.

p KeyError.new(key: :unknown_key).key
# => :unknown_key

key_error = KeyError.new(receiver: Object.new, key: :unknown_key)
p key_error.receiver
# => The Object instance.
p key_error.key
# => :unknown_key

key_error = KeyError.new("Message", receiver: Object.new, key: :unknown_key)
p key_error.message
# => "Message"
p key_error.receiver
# => The Object instance.
p key_error.key
# => :unknown_key
```


---Files--------------------------------
key_error_new.diff (2.91 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next