Exception: RailsFlowMap::Error

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

Overview

Base error class for all RailsFlowMap errors

This class provides a common interface for all errors raised by the RailsFlowMap gem, including error categorization, context preservation, and structured error reporting.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, context: {}, error_code: nil, category: :general) ⇒ Error

Initialize a new error with context and categorization

Parameters:

  • message (String)

    The error message

  • context (Hash) (defaults to: {})

    Additional context about the error

  • error_code (String) (defaults to: nil)

    Unique error code for programmatic handling

  • category (Symbol) (defaults to: :general)

    Error category for classification



18
19
20
21
22
23
# File 'lib/rails_flow_map/errors.rb', line 18

def initialize(message, context: {}, error_code: nil, category: :general)
  super(message)
  @context = context
  @error_code = error_code || self.class.name.split('::').last.downcase
  @category = category
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



10
11
12
# File 'lib/rails_flow_map/errors.rb', line 10

def category
  @category
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/rails_flow_map/errors.rb', line 10

def context
  @context
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



10
11
12
# File 'lib/rails_flow_map/errors.rb', line 10

def error_code
  @error_code
end

Instance Method Details

#to_hHash

Returns Full error information including context.

Returns:

  • (Hash)

    Full error information including context



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails_flow_map/errors.rb', line 26

def to_h
  {
    error_class: self.class.name,
    message: message,
    error_code: error_code,
    category: category,
    context: context,
    backtrace: backtrace&.first(10)
  }
end

#to_json(*args) ⇒ String

Returns JSON representation of the error.

Returns:

  • (String)

    JSON representation of the error



38
39
40
41
# File 'lib/rails_flow_map/errors.rb', line 38

def to_json(*args)
  require 'json'
  to_h.to_json(*args)
end