Navigation Menu

Skip to content

Commit

Permalink
Report invalid result type error
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2012
1 parent fd04225 commit fb46af6
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions lib/grntest/tester.rb
Expand Up @@ -31,6 +31,27 @@

module Grntest
class Tester
class Error < StandardError
end

class NotExist < Error
attr_reader :path
def initialize(path)
@path = path
super("<#{path}> doesn't exist.")
end
end

class ParseError < Error
attr_reader :type, :content, :reason
def initialize(type, content, reason)
@type = type
@content = content
@reason = reason
super("failed to parse <#{@type}> content: #{reason}: <#{content}>")
end
end

class << self
def run(argv=nil)
argv ||= ARGV.dup
Expand Down Expand Up @@ -952,7 +973,13 @@ def normalize_output(content, options)
type = options[:type]
case type
when "json", "msgpack"
status, *values = parse_result(content, type)
status = nil
values = nil
begin
status, *values = parse_result(content.chomp, type)
rescue ParseError
return $!.message
end
normalized_status = normalize_status(status)
normalized_output_content = [normalized_status, *values]
normalized_output = JSON.generate(normalized_output_content)
Expand All @@ -968,11 +995,19 @@ def normalize_output(content, options)
def parse_result(result, type)
case type
when "json"
JSON.parse(result)
begin
JSON.parse(result)
rescue JSON::ParserError
raise ParseError.new(type, result, $!.message)
end
when "msgpack"
MessagePack.unpack(result.chomp)
begin
MessagePack.unpack(result.chomp)
rescue MessagePack::UnpackError, NoMemoryError
raise ParseError.new(type, result, $!.message)
end
else
raise "Unknown type: #{type}"
raise ParseError.new(type, result, "unknown type")
end
end

Expand Down Expand Up @@ -1083,17 +1118,6 @@ def relative_db_path
end
end

class Error < StandardError
end

class NotExist < Error
attr_reader :path
def initialize(path)
@path = path
super("<#{path}> doesn't exist.")
end
end

attr_reader :context
def initialize(context=nil)
@loading = false
Expand Down

0 comments on commit fb46af6

Please sign in to comment.