Exception: RailsConsoleAi::SafetyError
- Inherits:
-
StandardError
- Object
- StandardError
- RailsConsoleAi::SafetyError
- 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
-
#blocked_key ⇒ Object
readonly
Returns the value of attribute blocked_key.
-
#guard ⇒ Object
readonly
Returns the value of attribute guard.
Class Method Summary collapse
- .clear! ⇒ Object
-
.last_raised ⇒ Object
Thread-local tracking so the executor can detect safety errors even when swallowed by a rescue inside eval’d code.
Instance Method Summary collapse
-
#initialize(message, guard: nil, blocked_key: nil) ⇒ SafetyError
constructor
A new instance of SafetyError.
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(, guard: nil, blocked_key: nil) super() @guard = guard @blocked_key = blocked_key Thread.current[:rails_console_ai_last_safety_error] = self end |
Instance Attribute Details
#blocked_key ⇒ Object (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 |
#guard ⇒ Object (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_raised ⇒ Object
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 |