diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-21 23:57:28 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-21 23:57:28 +0000 |
commit | e2eb456f51294a136a21e48af242f4f3eb27badd (patch) | |
tree | de9859c8df048ca492ac38f08d4004b4fc92846d /lib/custodian/protocoltest.rb | |
parent | f10ec95a1fafbb0ff36f794e8f08642fc741a0ae (diff) |
Catch errors in deserialization
Diffstat (limited to 'lib/custodian/protocoltest.rb')
-rw-r--r-- | lib/custodian/protocoltest.rb | 10 |
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 |