summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog8
-rw-r--r--array.c11
-rw-r--r--hash.c6
3 files changed, 19 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 9ade4b72ca..2f5dd92a30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat May 8 13:48:31 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * 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
+
Sat May 8 13:11:28 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rubygems/user_interaction.rb (Gem::StreamUI#ask_for_password):
diff --git a/array.c b/array.c
index 4bb4fcb838..068eb6c29a 100644
--- a/array.c
+++ b/array.c
@@ -616,8 +616,8 @@ rb_ary_store(VALUE ary, long idx, VALUE val)
if (idx < 0) {
idx += RARRAY_LEN(ary);
if (idx < 0) {
- rb_raise(rb_eIndexError, "index %ld out of array",
- idx - RARRAY_LEN(ary));
+ rb_raise(rb_eIndexError, "index %ld too small for array; minimum: %ld",
+ idx - RARRAY_LEN(ary), -RARRAY_LEN(ary));
}
}
else if (idx >= ARY_MAX_SIZE) {
@@ -1133,7 +1133,8 @@ rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
if (idx < 0 || RARRAY_LEN(ary) <= idx) {
if (block_given) return rb_yield(pos);
if (argc == 1) {
- rb_raise(rb_eIndexError, "index %ld out of array", idx);
+ rb_raise(rb_eIndexError, "index %ld outside of array bounds: %ld...%ld",
+ idx - (idx < 0 ? RARRAY_LEN(ary) : 0), -RARRAY_LEN(ary), RARRAY_LEN(ary));
}
return ifnone;
}
@@ -1246,8 +1247,8 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
if (beg < 0) {
beg += RARRAY_LEN(ary);
if (beg < 0) {
- beg -= RARRAY_LEN(ary);
- rb_raise(rb_eIndexError, "index %ld out of array", beg);
+ rb_raise(rb_eIndexError, "index %ld too small for array; minimum: %ld",
+ beg - RARRAY_LEN(ary), -RARRAY_LEN(ary));
}
}
if (RARRAY_LEN(ary) < len || RARRAY_LEN(ary) < beg + len) {
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;
}