From c5275175987b8d2e1fe499c5d2095988a90b35ef Mon Sep 17 00:00:00 2001 From: Phil Schalm <131064104+phil-janeapp@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:15:36 -0800 Subject: [PATCH] Fix some load errors related to different gem versions being available (#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 --- lib/dip/config.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/dip/config.rb b/lib/dip/config.rb index 3437a94..2d5536f 100644 --- a/lib/dip/config.rb +++ b/lib/dip/config.rb @@ -120,8 +120,8 @@ 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}" @@ -129,6 +129,8 @@ def validate 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