Skip to content

Commit

Permalink
do not ignore decode errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Majakari authored and defunkt committed Mar 17, 2011
1 parent 9377687 commit 3d9daa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/resque/helpers.rb
@@ -1,6 +1,8 @@
module Resque
# Methods used by various classes in Resque.
module Helpers
class DecodeException < StandardError; end

# Direct access to the Redis instance.
def redis
Resque.redis
Expand All @@ -23,12 +25,14 @@ def decode(object)
if defined? Yajl
begin
Yajl::Parser.parse(object, :check_utf8 => false)
rescue Yajl::ParseError
rescue Yajl::ParseError => e
raise DecodeException, e
end
else
begin
JSON.parse(object)
rescue JSON::ParserError
rescue JSON::ParserError => e
raise DecodeException, e
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/resque_test.rb
Expand Up @@ -233,6 +233,8 @@
end

test "decode bad json" do
assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
assert_raises Resque::Helpers::DecodeException do
Resque.decode("{\"error\":\"Module not found \\u002\"}")
end
end
end

0 comments on commit 3d9daa8

Please sign in to comment.