Class: RegoValidate::ErrorReporter::ErrorPayload
- Inherits:
-
Object
- Object
- RegoValidate::ErrorReporter::ErrorPayload
- Defined in:
- lib/ruby/rego/cli/reporting.rb
Overview
Serializes error details for JSON output.
Class Method Summary collapse
-
.from_cli_error(message) ⇒ ErrorPayload
Build a payload for a CLI error message.
-
.from_rego_error(error) ⇒ ErrorPayload
Build a payload for a Rego error.
Instance Method Summary collapse
-
#initialize(message:, type:, location: nil) ⇒ ErrorPayload
constructor
A new instance of ErrorPayload.
-
#to_h ⇒ Hash{Symbol => Object}
Constructor Details
#initialize(message:, type:, location: nil) ⇒ ErrorPayload
Returns a new instance of ErrorPayload.
143 144 145 146 147 |
# File 'lib/ruby/rego/cli/reporting.rb', line 143 def initialize(message:, type:, location: nil) @message = @type = type @location = location end |
Class Method Details
.from_cli_error(message) ⇒ ErrorPayload
Build a payload for a CLI error message.
128 129 130 |
# File 'lib/ruby/rego/cli/reporting.rb', line 128 def self.from_cli_error() new(message: , type: "CLIError") end |
.from_rego_error(error) ⇒ ErrorPayload
Build a payload for a Rego error.
136 137 138 |
# File 'lib/ruby/rego/cli/reporting.rb', line 136 def self.from_rego_error(error) new(message: error., type: error.class.name, location: error.location) end |
Instance Method Details
#to_h ⇒ Hash{Symbol => Object}
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ruby/rego/cli/reporting.rb', line 150 def to_h payload = { success: false, error: , type: type } return payload unless location payload.merge( location: location.to_s, line: location.line, column: location.column ) end |