Class: RegoValidate::ErrorReporter::ErrorPayload
- Inherits:
-
Object
- Object
- RegoValidate::ErrorReporter::ErrorPayload
- Defined in:
- lib/ruby/rego/cli.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.
1010 1011 1012 1013 1014 |
# File 'lib/ruby/rego/cli.rb', line 1010 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.
995 996 997 |
# File 'lib/ruby/rego/cli.rb', line 995 def self.from_cli_error() new(message: , type: "CLIError") end |
.from_rego_error(error) ⇒ ErrorPayload
Build a payload for a Rego error.
1003 1004 1005 |
# File 'lib/ruby/rego/cli.rb', line 1003 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}
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
# File 'lib/ruby/rego/cli.rb', line 1017 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 |