ruby-changes:29973
From: nobu <ko1@a...>
Date: Wed, 17 Jul 2013 17:12:42 +0900 (JST)
Subject: [ruby-changes:29973] nobu:r42025 (trunk): hash.c: key name in error message
nobu 2013-07-17 17:12:25 +0900 (Wed, 17 Jul 2013) New Revision: 42025 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42025 Log: hash.c: key name in error message * hash.c (env_fetch): Add key name to message on ENV.fetch KeyError, as well as Hash#fetch. [ruby-core:56062] [Feature #8649] Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_env.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42024) +++ ChangeLog (revision 42025) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 17 17:12:23 2013 Matthew M. Boedicker <matthewm@b...> + + * hash.c (env_fetch): Add key name to message on ENV.fetch KeyError, + as well as Hash#fetch. [ruby-core:56062] [Feature #8649] + Wed Jul 17 15:59:33 2013 Koichi Sasada <ko1@a...> * gc.c: catch up last changes for debugging/checking mode. Index: hash.c =================================================================== --- hash.c (revision 42024) +++ hash.c (revision 42025) @@ -2411,7 +2411,7 @@ env_fetch(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/hash.c#L2411 if (!env) { if (block_given) return rb_yield(key); if (argc == 1) { - rb_raise(rb_eKeyError, "key not found"); + rb_raise(rb_eKeyError, "key not found: \"%"PRIsVALUE"\"", key); } return if_none; } Index: test/ruby/test_env.rb =================================================================== --- test/ruby/test_env.rb (revision 42024) +++ test/ruby/test_env.rb (revision 42025) @@ -103,7 +103,10 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L103 ENV["test"] = "foo" assert_equal("foo", ENV.fetch("test")) ENV.delete("test") - assert_raise(KeyError) { ENV.fetch("test") } + feature8649 = '[ruby-core:56062] [Feature #8649]' + assert_raise_with_message(KeyError, 'key not found: "test"', feature8649) do + ENV.fetch("test") + end assert_equal("foo", ENV.fetch("test", "foo")) assert_equal("bar", ENV.fetch("test") { "bar" }) assert_equal("bar", ENV.fetch("test", "foo") { "bar" }) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/