diff --git a/ChangeLog b/ChangeLog index 335c61962c..95c19c0936 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 17 17:12:23 2013 Matthew M. Boedicker + + * 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 * gc.c: catch up last changes for debugging/checking mode. diff --git a/hash.c b/hash.c index 6cddb8cf0b..e170e67660 100644 --- a/hash.c +++ b/hash.c @@ -2411,7 +2411,7 @@ env_fetch(int argc, VALUE *argv) 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; } diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index f6fcaace11..17c5d57d25 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -103,7 +103,10 @@ class TestEnv < Test::Unit::TestCase 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" })