From a39ae5f9734d72bc6101597a33f0594b9d41105a Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 21 Nov 2012 23:57:28 +0000 Subject: Catch errors in deserialization --- lib/custodian/protocoltest.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/custodian') diff --git a/lib/custodian/protocoltest.rb b/lib/custodian/protocoltest.rb index 9efeb0f..7c631c8 100644 --- a/lib/custodian/protocoltest.rb +++ b/lib/custodian/protocoltest.rb @@ -34,8 +34,14 @@ class ProtocolTest # JSON ? # if ( line =~ /^\{(.*)\}$/ ) - obj = JSON.parse( line ); - line = obj["line"] + begin + obj = JSON.parse( line ); + raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash) + line = obj["line"] + raise ArgumentError, "obj[:line] was nil" unless (!line.nil?) + rescue =>ex + raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}" + end end -- cgit v1.2.1