summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-21 23:57:28 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-21 23:57:28 +0000
commita39ae5f9734d72bc6101597a33f0594b9d41105a (patch)
treede9859c8df048ca492ac38f08d4004b4fc92846d /lib
parent6c11958ab96a8a0f0b75bfd5fee21dbb3fdf2eec (diff)
Catch errors in deserialization
Diffstat (limited to 'lib')
-rw-r--r--lib/custodian/protocoltest.rb10
1 files changed, 8 insertions, 2 deletions
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