Remove rescue block and add test for error bubbling in InputSchema validation
This commit is contained in:
parent
600c96f66a
commit
934a5e8db4
2 changed files with 18 additions and 12 deletions
|
|
@ -38,18 +38,14 @@ module MCP
|
|||
|
||||
def validate_schema!
|
||||
schema = to_h
|
||||
begin
|
||||
schema_reader = JSON::Schema::Reader.new(
|
||||
accept_uri: false,
|
||||
accept_file: ->(path) { path.to_s.start_with?(Gem.loaded_specs["json-schema"].full_gem_path) },
|
||||
)
|
||||
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
|
||||
errors = JSON::Validator.fully_validate(metaschema, schema, schema_reader: schema_reader)
|
||||
if errors.any?
|
||||
raise ArgumentError, "Invalid JSON Schema: #{errors.join(", ")}"
|
||||
end
|
||||
rescue StandardError => e
|
||||
raise ArgumentError, "Invalid JSON Schema: #{e.message}"
|
||||
schema_reader = JSON::Schema::Reader.new(
|
||||
accept_uri: false,
|
||||
accept_file: ->(path) { path.to_s.start_with?(Gem.loaded_specs["json-schema"].full_gem_path) },
|
||||
)
|
||||
metaschema = JSON::Validator.validator_for_name("draft4").metaschema
|
||||
errors = JSON::Validator.fully_validate(metaschema, schema, schema_reader: schema_reader)
|
||||
if errors.any?
|
||||
raise ArgumentError, "Invalid JSON Schema: #{errors.join(", ")}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,6 +51,16 @@ module MCP
|
|||
schema.validate_arguments({ foo: 123 })
|
||||
end
|
||||
end
|
||||
|
||||
test "unexpected errors bubble up from validate_arguments" do
|
||||
schema = InputSchema.new(properties: { foo: { type: "string" } }, required: [:foo])
|
||||
|
||||
JSON::Validator.stub(:fully_validate, ->(*) { raise "unexpected error" }) do
|
||||
assert_raises(RuntimeError) do
|
||||
schema.validate_arguments({ foo: "bar" })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue