thrift-validator 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d2072d19fcac9ac4d9e44efc3d1a9b360fde931
4
- data.tar.gz: 861205ed86104587b4a8fe319f5771c95f9733a4
3
+ metadata.gz: c4e1c8126e551341a317cadd64f4808072bf943b
4
+ data.tar.gz: 477cce1e6c427a3a9464c95f2d00430baf236e24
5
5
  SHA512:
6
- metadata.gz: b038a575a75faeb0b986f76ce8dfb265d8a31bcdc45d80cd51fed0ff459708096b2ecae3b0ec8cec266b70d441bfff634c4ab141087ff37ade1cae552386f583
7
- data.tar.gz: 05ee95200e54ff7a6a027a58d160b2fecc15b341e80f0480a9cae6856f1278b9b1383ea25ed922df99ce6c708a74e3cf31f1ffc8ea134e1925888d80685534e0
6
+ metadata.gz: 4053c7fad656046a406d9d81681a106c30d53506abc9071a7fad2195dda4398fb92ce64aacafbe0a7b7c00675b86982e5575812d6f95e8e30cb8fe4e927cfe35
7
+ data.tar.gz: b776e8638590c4a59b297e9730d9bcc41f153f1741efa4919688d240998644347246929f8851cff8c4ef7d20dedf786f15d474af6f577b4d24b842ccfced5e8b
@@ -4,7 +4,12 @@ require 'thrift'
4
4
  module Thrift
5
5
  class Validator
6
6
  def validate(source)
7
- source.validate
7
+ begin
8
+ source.validate
9
+ rescue Thrift::ProtocolException => ex
10
+ message = "#{source.class.name}: #{ex}"
11
+ raise Thrift::ProtocolException.new(ex.type, message)
12
+ end
8
13
 
9
14
  source.struct_fields.each_pair do |_, field|
10
15
  type, name = field.fetch(:type), field.fetch(:name)
@@ -1,5 +1,5 @@
1
1
  module Thrift
2
2
  class Validator
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ExceptionsTest < MiniTest::Unit::TestCase
4
+ def test_exception_message_contains_class_name
5
+ # The error is in NestedExample - required_struct is unset
6
+ struct = NestedExample.new required_struct: nil
7
+
8
+ ex = assert_raises Thrift::ProtocolException do
9
+ Thrift::Validator.new.validate(struct)
10
+ end
11
+ assert_match /NestedExample/, ex.message
12
+ end
13
+
14
+ def test_exception_message_contains_nested_class_name
15
+ # Here NestedExample is valid, but the error is one level down
16
+ # in SimpleStruct (its required_string is unset)
17
+ struct = NestedExample.new
18
+ struct.required_struct = SimpleStruct.new required_string: nil
19
+
20
+ ex = assert_raises Thrift::ProtocolException do
21
+ Thrift::Validator.new.validate(struct)
22
+ end
23
+ assert_match /SimpleStruct/, ex.message
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ahawkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift
@@ -70,6 +70,7 @@ files:
70
70
  - lib/thrift/validator/version.rb
71
71
  - test.thrift
72
72
  - test/acceptance_test.rb
73
+ - test/exceptions_test.rb
73
74
  - test/test_helper.rb
74
75
  - thrift-validator.gemspec
75
76
  - vendor/gen-rb/test_constants.rb
@@ -100,4 +101,5 @@ specification_version: 4
100
101
  summary: Recursive thrift struct validator
101
102
  test_files:
102
103
  - test/acceptance_test.rb
104
+ - test/exceptions_test.rb
103
105
  - test/test_helper.rb