summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 04:58:18 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 04:58:18 +0000
commite9650c0b077707168095891af6419ca148b94b38 (patch)
treef1850bf2e50690e592bd03f043585b3eb9278bd5 /hash.c
parent4832574b9272933259c841121f4780eb876d8863 (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/branches/ruby_1_9_2@27672 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;
}