Exception: RailsConsoleAi::SafetyError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rails_console_ai/safety_guards.rb

Overview

Raised by safety guards to block dangerous operations. Host apps should raise this error in their custom guards. RailsConsoleAi will catch it and guide the user to use ‘d’ or /danger.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, guard: nil, blocked_key: nil) ⇒ SafetyError

Returns a new instance of SafetyError.



18
19
20
21
22
23
# File 'lib/rails_console_ai/safety_guards.rb', line 18

def initialize(message, guard: nil, blocked_key: nil)
  super(message)
  @guard = guard
  @blocked_key = blocked_key
  Thread.current[:rails_console_ai_last_safety_error] = self
end

Instance Attribute Details

#blocked_keyObject (readonly)

Returns the value of attribute blocked_key.



6
7
8
# File 'lib/rails_console_ai/safety_guards.rb', line 6

def blocked_key
  @blocked_key
end

#guardObject (readonly)

Returns the value of attribute guard.



6
7
8
# File 'lib/rails_console_ai/safety_guards.rb', line 6

def guard
  @guard
end

Class Method Details

.clear!Object



14
15
16
# File 'lib/rails_console_ai/safety_guards.rb', line 14

def self.clear!
  Thread.current[:rails_console_ai_last_safety_error] = nil
end

.last_raisedObject

Thread-local tracking so the executor can detect safety errors even when swallowed by a rescue inside eval’d code.



10
11
12
# File 'lib/rails_console_ai/safety_guards.rb', line 10

def self.last_raised
  Thread.current[:rails_console_ai_last_safety_error]
end