Class: RailsErrorDashboard::Services::MarkdownErrorFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/services/markdown_error_formatter.rb

Overview

Pure algorithm: Format error details as clean Markdown for LLM debugging

Reads data already stored in ErrorLog — zero runtime cost. Called at display time only. Sections are conditional — only included when data is present.

Examples:

RailsErrorDashboard::Services::MarkdownErrorFormatter.call(error, related_errors: related)
# => "# NoMethodError\n\nundefined method 'foo' for nil\n\n## Backtrace\n\n..."

Constant Summary collapse

MAX_BACKTRACE_LINES =
15
MAX_BREADCRUMBS =
10
MAX_VARIABLES =
10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, related_errors) ⇒ MarkdownErrorFormatter

Returns a new instance of MarkdownErrorFormatter.



28
29
30
31
# File 'lib/rails_error_dashboard/services/markdown_error_formatter.rb', line 28

def initialize(error, related_errors)
  @error = error
  @related_errors = related_errors
end

Class Method Details

.call(error, related_errors: []) ⇒ String

Returns Markdown-formatted error details, or “” on failure.

Parameters:

  • error (ErrorLog)

    An error log record

  • related_errors (Array) (defaults to: [])

    Related error results with :error and :similarity

Returns:

  • (String)

    Markdown-formatted error details, or “” on failure



22
23
24
25
26
# File 'lib/rails_error_dashboard/services/markdown_error_formatter.rb', line 22

def self.call(error, related_errors: [])
  new(error, related_errors).generate
rescue => e
  ""
end

Instance Method Details

#generateString

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rails_error_dashboard/services/markdown_error_formatter.rb', line 34

def generate
  sections = []

  sections << heading_section
  sections << backtrace_section
  sections << source_code_section
  sections << cause_chain_section
  sections << local_variables_section
  sections << instance_variables_section
  sections << request_context_section
  sections << breadcrumbs_section
  sections << environment_section
  sections << system_health_section
  sections << related_errors_section
  sections << 

  sections.compact.join("\n\n")
rescue => e
  ""
end