Class: RegoValidate::ErrorReporter::ErrorPayload

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/cli.rb

Overview

Serializes error details for JSON output.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, type:, location: nil) ⇒ ErrorPayload

Returns a new instance of ErrorPayload.

Parameters:



1010
1011
1012
1013
1014
# File 'lib/ruby/rego/cli.rb', line 1010

def initialize(message:, type:, location: nil)
  @message = message
  @type = type
  @location = location
end

Class Method Details

.from_cli_error(message) ⇒ ErrorPayload

Build a payload for a CLI error message.

Parameters:

  • message (String)

Returns:



995
996
997
# File 'lib/ruby/rego/cli.rb', line 995

def self.from_cli_error(message)
  new(message: message, type: "CLIError")
end

.from_rego_error(error) ⇒ ErrorPayload

Build a payload for a Rego error.

Parameters:

Returns:



1003
1004
1005
# File 'lib/ruby/rego/cli.rb', line 1003

def self.from_rego_error(error)
  new(message: error.message, type: error.class.name, location: error.location)
end

Instance Method Details

#to_hHash{Symbol => Object}

Returns:

  • (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: message, type: type }
  return payload unless location

  payload.merge(
    location: location.to_s,
    line: location.line,
    column: location.column
  )
end