Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AVRO-1258. Ruby: Fix handing of RPC errors. Contributed by Martin Kle…

…ppmann.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1447958 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 8e8de3360c93cca2b6e2877f96423cdf0b48e747 1 parent a78127b
@cutting cutting authored
View
2  CHANGES.txt
@@ -91,6 +91,8 @@ Trunk (not yet released)
AVRO-1257. Ruby: Fix UTF-8 encoding in Ruby 1.9.
(Martin Kleppmann via cutting)
+ AVRO-1258. Ruby: Fix handing of RPC errors. (Martin Kleppmann via cutting)
+
Avro 1.7.3 (6 December 2012)
NEW FEATURES
View
10 lang/ruby/lib/avro/io.rb
@@ -245,7 +245,7 @@ def self.match_schemas(writers_schema, readers_schema)
when 'record'
return check_props(writers_schema, readers_schema, [:fullname])
when 'error'
- return check_props(writers_scheam, readers_schema, [:fullname])
+ return check_props(writers_schema, readers_schema, [:fullname])
when 'request'
return true
when 'fixed'
@@ -315,7 +315,7 @@ def read_data(writers_schema, readers_schema, decoder)
when 'array'; read_array(writers_schema, readers_schema, decoder)
when 'map'; read_map(writers_schema, readers_schema, decoder)
when 'union'; read_union(writers_schema, readers_schema, decoder)
- when 'record', 'errors', 'request'; read_record(writers_schema, readers_schema, decoder)
+ when 'record', 'error', 'request'; read_record(writers_schema, readers_schema, decoder)
else
raise AvroError, "Cannot read unknown schema type: #{writers_schema.type}"
end
@@ -443,7 +443,7 @@ def read_default_value(field_schema, default_value)
return read_map
when 'union'
return read_default_value(field_schema.schemas[0], default_value)
- when 'record'
+ when 'record', 'error'
read_record = {}
field_schema.fields.each do |field|
json_val = default_value[field.name]
@@ -454,7 +454,7 @@ def read_default_value(field_schema, default_value)
return read_record
else
fail_msg = "Unknown type: #{field_schema.type}"
- raise AvroError(fail_msg)
+ raise AvroError, fail_msg
end
end
@@ -566,7 +566,7 @@ def write_data(writers_schema, datum, encoder)
when 'array'; write_array(writers_schema, datum, encoder)
when 'map'; write_map(writers_schema, datum, encoder)
when 'union'; write_union(writers_schema, datum, encoder)
- when 'record', 'errors', 'request'; write_record(writers_schema, datum, encoder)
+ when 'record', 'error', 'request'; write_record(writers_schema, datum, encoder)
else
raise AvroError.new("Unknown type: #{writers_schema.type}")
end
View
2  lang/ruby/test/random_data.rb
@@ -58,7 +58,7 @@ def nextdata(schm, d=0)
map[nextdata(Avro::Schema::PrimitiveSchema.new('string'))] = nextdata(schm.values, d+1)
end
map
- when 'record'
+ when 'record', 'error'
m = {}
schm.fields.each do |field|
m[field.name] = nextdata(field.type, d+1)
View
10 lang/ruby/test/test_io.rb
@@ -73,6 +73,16 @@ def test_record
check_default(record_schema, '{"f": 11}', {"f" => 11})
end
+ def test_error
+ error_schema = <<EOS
+ {"type": "error",
+ "name": "TestError",
+ "fields": [{"name": "message",
+ "type": "string"}]}
+EOS
+ check_default(error_schema, '{"message": "boom"}', {"message" => "boom"})
+ end
+
def test_enum
enum_schema = '{"type": "enum", "name": "Test","symbols": ["A", "B"]}'
check_default(enum_schema, '"B"', "B")
Please sign in to comment.
Something went wrong with that request. Please try again.