Exception: Kube::ValidationError
- Defined in:
- lib/kube/errors.rb
Overview
Raised by Resource#valid! when data fails schema validation.
Produces detailed, human-readable error messages that identify the exact key path and offending value, followed by the resource YAML with error lines highlighted in red and missing keys injected inline.
Schema validation failed for Deployment "web":
- spec.selector is required but missing
- spec.replicas = "not_a_number" — expected integer, got String
---
apiVersion: apps/v1
kind: Deployment
spec:
selector: # MISSING — required
replicas: "nah" # expected integer, got String
Constant Summary collapse
- RED =
"\033[31m"- YELLOW =
"\033[33m"- RESET =
"\033[0m"- BOLD =
"\033[1m"- UNDERLINE =
"\033[4m"
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#detailed_message(highlight: false) ⇒ Object
Ruby 3.2+ calls detailed_message for uncaught exceptions.
-
#initialize(errors, kind: nil, name: nil, manifest: nil) ⇒ ValidationError
constructor
A new instance of ValidationError.
Constructor Details
#initialize(errors, kind: nil, name: nil, manifest: nil) ⇒ ValidationError
Returns a new instance of ValidationError.
46 47 48 49 50 51 52 |
# File 'lib/kube/errors.rb', line 46 def initialize(errors, kind: nil, name: nil, manifest: nil) @errors = errors @kind = kind @name = name @manifest = manifest super() end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
33 34 35 |
# File 'lib/kube/errors.rb', line 33 def errors @errors end |
Instance Method Details
#detailed_message(highlight: false) ⇒ Object
Ruby 3.2+ calls detailed_message for uncaught exceptions. We override it so the message ends at column 0, preventing Ruby from indenting the backtrace to match YAML indentation.
57 58 59 60 61 62 63 64 65 |
# File 'lib/kube/errors.rb', line 57 def (highlight: false, **) out = "\n#{BOLD}#{UNDERLINE}#{RED}#{header_line}#{RESET}\n\n" out += error_lines.join("\n") if @manifest out += "\n\n#{annotate_manifest(@manifest, @errors)}" end out += "\n\n" out end |