[前][次][番号順一覧][スレッド一覧]

ruby-changes:15744

From: marcandre <ko1@a...>
Date: Sat, 8 May 2010 13:58:34 +0900 (JST)
Subject: [ruby-changes:15744] Ruby:r27672 (ruby_1_9_2): * array.c (rb_ary_fetch, rb_ary_splice, rb_ary_store): Improve IndexError

marcandre	2010-05-08 13:58:18 +0900 (Sat, 08 May 2010)

  New Revision: 27672

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27672

  Log:
    * 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

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/array.c
    branches/ruby_1_9_2/hash.c

Index: ruby_1_9_2/array.c
===================================================================
--- ruby_1_9_2/array.c	(revision 27671)
+++ ruby_1_9_2/array.c	(revision 27672)
@@ -616,8 +616,8 @@
     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 @@
     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 @@
     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) {
Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 27671)
+++ ruby_1_9_2/ChangeLog	(revision 27672)
@@ -1,3 +1,10 @@
+Sat May  8 13:48:31 2010  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* 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 11:07:41 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
Index: ruby_1_9_2/hash.c
===================================================================
--- ruby_1_9_2/hash.c	(revision 27671)
+++ ruby_1_9_2/hash.c	(revision 27672)
@@ -570,7 +570,11 @@
     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;
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]