Class: RosettAi::ErrorHandler
- Inherits:
-
Object
- Object
- RosettAi::ErrorHandler
- Defined in:
- lib/rosett_ai/error_handler.rb
Overview
Centralized error handler for CLI commands.
Catches +RosettAi::Error+ (and subclasses), formats the error message with what/why/fix structure, and exits with the mapped exit code. Stack traces are only shown when +RAI_LOG_LEVEL=DEBUG+.
TTY-aware: uses colour and formatting when stdout is a TTY, plain text when piped.
Class Method Summary collapse
-
.handle(stderr: $stderr) { ... } ⇒ Integer
Wraps a block, rescuing +RosettAi::Error+ and formatting the output.
Instance Method Summary collapse
-
#handle { ... } ⇒ Integer
Executes the block and handles errors.
-
#initialize(stderr: $stderr) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(stderr: $stderr) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
31 32 33 |
# File 'lib/rosett_ai/error_handler.rb', line 31 def initialize(stderr: $stderr) @stderr = stderr end |
Class Method Details
.handle(stderr: $stderr) { ... } ⇒ Integer
Wraps a block, rescuing +RosettAi::Error+ and formatting the output.
26 27 28 |
# File 'lib/rosett_ai/error_handler.rb', line 26 def self.handle(stderr: $stderr, &) new(stderr: stderr).handle(&) end |