Exception: Aidp::Errors::PolicyViolation

Inherits:
StandardError
  • Object
show all
Defined in:
lib/aidp/errors.rb

Overview

Exception raised when a Rule of Two policy violation occurs Contains detailed context about the violation for logging and debugging

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flag:, source:, current_state:, message: nil) ⇒ PolicyViolation



20
21
22
23
24
25
26
27
# File 'lib/aidp/errors.rb', line 20

def initialize(flag:, source:, current_state:, message: nil)
  @flag = flag
  @source = source
  @current_state = current_state
  @suggested_mitigations = build_suggested_mitigations(flag, current_state)

  super(message || default_message)
end

Instance Attribute Details

#current_stateObject (readonly)

Returns the value of attribute current_state.



18
19
20
# File 'lib/aidp/errors.rb', line 18

def current_state
  @current_state
end

#flagObject (readonly)

Returns the value of attribute flag.



18
19
20
# File 'lib/aidp/errors.rb', line 18

def flag
  @flag
end

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/aidp/errors.rb', line 18

def source
  @source
end

#suggested_mitigationsObject (readonly)

Returns the value of attribute suggested_mitigations.



18
19
20
# File 'lib/aidp/errors.rb', line 18

def suggested_mitigations
  @suggested_mitigations
end

Instance Method Details

#to_hObject

Export violation details for logging



30
31
32
33
34
35
36
37
38
39
# File 'lib/aidp/errors.rb', line 30

def to_h
  {
    type: "rule_of_two_violation",
    flag_attempted: @flag,
    source: @source,
    current_state: @current_state,
    suggested_mitigations: @suggested_mitigations,
    timestamp: Time.now.iso8601
  }
end

#to_json(*args) ⇒ Object

JSON representation for structured logging



42
43
44
# File 'lib/aidp/errors.rb', line 42

def to_json(*args)
  to_h.to_json(*args)
end