Exception: BetterService::BetterServiceError
- Inherits:
-
StandardError
- Object
- StandardError
- BetterService::BetterServiceError
- Defined in:
- lib/better_service/errors/better_service_error.rb
Overview
Base exception class for all BetterService errors
This class provides rich error information including error codes, context, original errors, and structured metadata for debugging and logging.
Direct Known Subclasses
Errors::Configuration::ConfigurationError, Errors::Runtime::RuntimeError
Instance Attribute Summary collapse
-
#code ⇒ Symbol?
readonly
Error code for programmatic handling.
-
#context ⇒ Hash
readonly
Additional context about the error.
-
#original_error ⇒ Exception?
readonly
Original exception that caused this error.
-
#timestamp ⇒ Time
readonly
When the error was raised.
Instance Method Summary collapse
-
#backtrace ⇒ Array<String>
Override backtrace to include original error’s backtrace.
-
#detailed_message ⇒ String
Get detailed error message with context.
-
#initialize(message = nil, code: nil, original_error: nil, context: {}) ⇒ BetterServiceError
constructor
Initialize a new BetterService error.
-
#inspect ⇒ String
Enhanced inspect for debugging.
-
#to_h ⇒ Hash
Convert error to a structured hash.
Constructor Details
#initialize(message = nil, code: nil, original_error: nil, context: {}) ⇒ BetterServiceError
Initialize a new BetterService error
62 63 64 65 66 67 68 |
# File 'lib/better_service/errors/better_service_error.rb', line 62 def initialize( = nil, code: nil, original_error: nil, context: {}) super() @code = code @original_error = original_error @context = context || {} @timestamp = Time.current end |
Instance Attribute Details
#code ⇒ Symbol? (readonly)
Returns Error code for programmatic handling.
45 46 47 |
# File 'lib/better_service/errors/better_service_error.rb', line 45 def code @code end |
#context ⇒ Hash (readonly)
Returns Additional context about the error.
51 52 53 |
# File 'lib/better_service/errors/better_service_error.rb', line 51 def context @context end |
#original_error ⇒ Exception? (readonly)
Returns Original exception that caused this error.
48 49 50 |
# File 'lib/better_service/errors/better_service_error.rb', line 48 def original_error @original_error end |
#timestamp ⇒ Time (readonly)
Returns When the error was raised.
54 55 56 |
# File 'lib/better_service/errors/better_service_error.rb', line 54 def @timestamp end |
Instance Method Details
#backtrace ⇒ Array<String>
Override backtrace to include original error’s backtrace
106 107 108 109 110 111 112 113 114 |
# File 'lib/better_service/errors/better_service_error.rb', line 106 def backtrace trace = super || [] if original_error && original_error.backtrace trace + [ "--- Original Error Backtrace ---" ] + original_error.backtrace else trace end end |
#detailed_message ⇒ String
Get detailed error message with context
88 89 90 91 92 93 94 |
# File 'lib/better_service/errors/better_service_error.rb', line 88 def parts = [ ] parts << "Code: #{code}" if code parts << "Context: #{context.inspect}" if context.any? parts << "Original: #{original_error.class.name}: #{original_error.}" if original_error parts.join(" | ") end |
#inspect ⇒ String
Enhanced inspect for debugging
99 100 101 |
# File 'lib/better_service/errors/better_service_error.rb', line 99 def inspect "#<#{self.class.name}: #{}>" end |
#to_h ⇒ Hash
Convert error to a structured hash
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/better_service/errors/better_service_error.rb', line 73 def to_h { error_class: self.class.name, message: , code: code, timestamp: .iso8601, context: context, original_error: original_error_info, backtrace: backtrace&.first(10) || [] } end |