Class: Fractor::ErrorFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/fractor/error_formatter.rb

Overview

Formats error messages with rich context for debugging. Extracted from Supervisor to follow Single Responsibility Principle.

Examples:

Basic usage

formatter = ErrorFormatter.new
error_message = formatter.format(wrapped_ractor, error_result)

Instance Method Summary collapse

Instance Method Details

#format(wrapped_ractor, error_result) ⇒ String

Format error context with rich information for debugging.

Parameters:

  • wrapped_ractor (WrappedRactor)

    The worker that encountered the error

  • error_result (WorkResult)

    The error result

Returns:

  • (String)

    Formatted error message with context



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fractor/error_formatter.rb', line 16

def format(wrapped_ractor, error_result)
  timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
  worker_class = wrapped_ractor.worker_class
  worker_name = wrapped_ractor.name

  # Build contextual error message
  lines = [
    "=" * 80,
    "[#{timestamp}] ERROR PROCESSING WORK",
    "=" * 80,
    "Worker: #{worker_name} (#{worker_class})",
    "Work Item: #{error_result.work&.inspect || 'unknown'}",
    "Error: #{error_result.error}",
  ]

  # Add error category and severity if available
  if error_result.respond_to?(:error_category) && error_result.error_category
    lines << "Category: #{error_result.error_category}"
  end
  if error_result.respond_to?(:error_severity) && error_result.error_severity
    lines << "Severity: #{error_result.error_severity}"
  end

  # Add suggestions based on error type
  suggestion = suggest_fix_for(error_result)
  lines << "Suggestion: #{suggestion}" if suggestion

  lines << "=" * 80
  lines.join("\n")
end