Skip to content

Commit

Permalink
AVRO-1645. Ruby: Improved handling of missing named types. Contribute…
Browse files Browse the repository at this point in the history
…d by Daniel Schierbeck.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1689884 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tomwhite committed Jul 8, 2015
1 parent 9e9f0e8 commit d3f8544
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -87,6 +87,9 @@ Trunk (not yet released)
AVRO-1681. Improve generated JavaDocs.
(Charles Gariépy-Ikeson via tomwhite)

AVRO-1645. Ruby: Improved handling of missing named types.
(Daniel Schierbeck via tomwhite)

BUG FIXES

AVRO-1553. Java: MapReduce never uses MapOutputValueSchema (tomwhite)
Expand Down
12 changes: 10 additions & 2 deletions lang/ruby/lib/avro/schema.rb
Expand Up @@ -86,8 +86,7 @@ def self.real_parse(json_obj, names=nil, default_namespace=nil)
elsif PRIMITIVE_TYPES.include? json_obj
return PrimitiveSchema.new(json_obj)
else
msg = "#{json_obj.inspect} is not a schema we know about."
raise SchemaParseError.new(msg)
raise UnknownSchemaError.new(json_obj)
end
end

Expand Down Expand Up @@ -370,6 +369,15 @@ def to_avro(names=Set.new)

class SchemaParseError < AvroError; end

class UnknownSchemaError < SchemaParseError
attr_reader :type_name

def initialize(type)
@type_name = type
super("#{type.inspect} is not a schema we know about.")
end
end

module Name
def self.extract_namespace(name, namespace)
parts = name.split('.')
Expand Down
12 changes: 12 additions & 0 deletions lang/ruby/test/test_schema.rb
Expand Up @@ -131,4 +131,16 @@ def test_to_avro_includes_namespaces
]
}
end

def test_unknown_named_type
error = assert_raise Avro::UnknownSchemaError do
Avro::Schema.parse <<-SCHEMA
{"type": "record", "name": "my.name.space.Record", "fields": [
{"name": "reference", "type": "MissingType"}
]}
SCHEMA
end

assert_equal '"MissingType" is not a schema we know about.', error.message
end
end

0 comments on commit d3f8544

Please sign in to comment.