File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -38,18 +38,14 @@ def validate_arguments(arguments)
38
38
39
39
def validate_schema!
40
40
schema = to_h
41
- begin
42
- schema_reader = JSON ::Schema ::Reader . new (
43
- accept_uri : false ,
44
- accept_file : -> ( path ) { path . to_s . start_with? ( Gem . loaded_specs [ "json-schema" ] . full_gem_path ) } ,
45
- )
46
- metaschema = JSON ::Validator . validator_for_name ( "draft4" ) . metaschema
47
- errors = JSON ::Validator . fully_validate ( metaschema , schema , schema_reader : schema_reader )
48
- if errors . any?
49
- raise ArgumentError , "Invalid JSON Schema: #{ errors . join ( ", " ) } "
50
- end
51
- rescue StandardError => e
52
- raise ArgumentError , "Invalid JSON Schema: #{ e . message } "
41
+ schema_reader = JSON ::Schema ::Reader . new (
42
+ accept_uri : false ,
43
+ accept_file : -> ( path ) { path . to_s . start_with? ( Gem . loaded_specs [ "json-schema" ] . full_gem_path ) } ,
44
+ )
45
+ metaschema = JSON ::Validator . validator_for_name ( "draft4" ) . metaschema
46
+ errors = JSON ::Validator . fully_validate ( metaschema , schema , schema_reader : schema_reader )
47
+ if errors . any?
48
+ raise ArgumentError , "Invalid JSON Schema: #{ errors . join ( ", " ) } "
53
49
end
54
50
end
55
51
end
Original file line number Diff line number Diff line change @@ -51,6 +51,16 @@ class InputSchemaTest < ActiveSupport::TestCase
51
51
schema . validate_arguments ( { foo : 123 } )
52
52
end
53
53
end
54
+
55
+ test "unexpected errors bubble up from validate_arguments" do
56
+ schema = InputSchema . new ( properties : { foo : { type : "string" } } , required : [ :foo ] )
57
+
58
+ JSON ::Validator . stub ( :fully_validate , -> ( *) { raise "unexpected error" } ) do
59
+ assert_raises ( RuntimeError ) do
60
+ schema . validate_arguments ( { foo : "bar" } )
61
+ end
62
+ end
63
+ end
54
64
end
55
65
end
56
66
end
You can’t perform that action at this time.
0 commit comments