diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index eeb1f5e..450844a 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -421,7 +421,7 @@ module XGen oh[:args] = args doc = db_command(oh) return doc['retval'] if ok?(doc) - raise "Error with eval command: #{doc.inspect}" + raise OperationFailure, "eval failed: #{doc['errmsg']}" end # Rename collection +from+ to +to+. Meant to be called by diff --git a/test/test_db_api.rb b/test/test_db_api.rb index 1de2012..c6b7410 100644 --- a/test/test_db_api.rb +++ b/test/test_db_api.rb @@ -554,7 +554,7 @@ class DBAPITest < Test::Unit::TestCase assert_equal 2, @@db.eval(Code.new("return i;", {"i" => 2})) assert_equal 5, @@db.eval(Code.new("i + 3;", {"i" => 2})) - assert_raise RuntimeError do + assert_raise OperationFailure do @@db.eval("5 ++ 5;") end end @@ -613,6 +613,10 @@ class DBAPITest < Test::Unit::TestCase {"a" => nil, "count" => 1}, {"a" => 1, "count" => 1}] assert_equal expected, test.group(["a"], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }") + + assert_raise OperationFailure do + test.group([], {}, {}, "5 ++ 5") + end end def test_deref