Skip to content

Commit

Permalink
Fix some load errors related to different gem versions being available (
Browse files Browse the repository at this point in the history
#184)

* Fix some load errors

- Ensure we utilize the wrapper for `load_yaml` to deal with aliases properly
- Utilize `JSON::Validator.parse` as it handles MultiJson and other inconsistencies

* Handle JSON::Schema::JsonParseError being thrown
  • Loading branch information
phil-janeapp authored Nov 29, 2024
1 parent 445b045 commit c527517
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/dip/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ def validate
schema_path = File.join(File.dirname(__FILE__), "../../schema.json")
raise Dip::Error, "Schema file not found: #{schema_path}" unless File.exist?(schema_path)

data = YAML.load_file(file_path)
schema = JSON.parse(File.read(schema_path))
data = self.class.load_yaml(file_path)
schema = JSON::Validator.parse(File.read(schema_path))
JSON::Validator.validate!(schema, data)
rescue Psych::SyntaxError => e
raise Dip::Error, "Invalid YAML syntax in config file: #{e.message}"
rescue JSON::Schema::ValidationError => e
data_display = data ? data.to_yaml.gsub("\n", "\n ") : "nil"
error_message = "Schema validation failed: #{e.message}\nInput data:\n #{data_display}"
raise Dip::Error, error_message
rescue JSON::Schema::JsonParseError => e
raise Dip::Error, "Error parsing schema file: #{e.message}"
end

private
Expand Down

0 comments on commit c527517

Please sign in to comment.