Class: Textus::Doctor::Check::SchemaParseError

Inherits:
Textus::Doctor::Check show all
Defined in:
lib/textus/doctor/check/schema_parse_error.rb

Overview

Surfaces YAML parse failures for files in <store>/schemas/. Without this check, malformed schemas are silently skipped by other doctor checks (UnownedSchemaFields rescues, Schemas only checks filenames), leaving the operator with no signal that a schema is broken.

Instance Method Summary collapse

Methods inherited from Textus::Doctor::Check

#initialize, name_key

Constructor Details

This class inherits a constructor from Textus::Doctor::Check

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/textus/doctor/check/schema_parse_error.rb', line 9

def call
  dir = File.join(store.root, "schemas")
  return [] unless File.directory?(dir)

  Dir.glob(File.join(dir, "*.yaml")).each_with_object([]) do |path, out|
    Schema.load(path)
  rescue StandardError => e
    out << {
      "code" => "schema.parse_error",
      "level" => "error",
      "subject" => path,
      "message" => "schema failed to parse: #{e.class}: #{e.message}",
      "fix" => "fix the YAML at #{path} (check indentation, quoted scalars, and aliases)",
    }
  end
end