summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 04:49:53 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 04:49:53 +0000
commitb140b77926a6e62228f1152157d0348ff5724f89 (patch)
treececc3a8d7218330d3802f90e3d85b247780b10f2 /hash.c
parentadf6297ec815edc2a4270384f83f0d96e09f25a1 (diff)
* array.c (rb_ary_fetch, rb_ary_splice, rb_ary_store): Improve IndexError
messages [ruby-core:28394] * hash.c (rb_hash_fetch_m): Improve KeyError message git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 21344c5e57..354593457d 100644
--- a/hash.c
+++ b/hash.c
@@ -570,7 +570,11 @@ rb_hash_fetch_m(int argc, VALUE *argv, VALUE hash)
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
if (block_given) return rb_yield(key);
if (argc == 1) {
- rb_raise(rb_eKeyError, "key not found");
+ VALUE desc = rb_protect(rb_inspect, key, 0);
+ if (NIL_P(desc) || RSTRING_LEN(desc) > 65) {
+ desc = rb_any_to_s(key);
+ }
+ rb_raise(rb_eKeyError, "key not found: %s", RSTRING_PTR(desc));
}
return if_none;
}