summaryrefslogtreecommitdiff
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
commite2eb456f51294a136a21e48af242f4f3eb27badd (patch)
treede9859c8df048ca492ac38f08d4004b4fc92846d
parentf10ec95a1fafbb0ff36f794e8f08642fc741a0ae (diff)
Catch errors in deserialization
-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