Class: Charming::Components::ErrorScreen

Inherits:
Charming::Component show all
Defined in:
lib/charming/presentation/components/error_screen.rb

Overview

ErrorScreen renders an unhandled exception as a styled, centered panel instead of letting the backtrace crash into the raw terminal. Shows the exception class, message, the most relevant backtrace lines, and a dismiss hint. The Runtime displays it when a dispatched action raises and no ‘rescue_from` handler claimed the exception.

Constant Summary collapse

DEFAULT_WIDTH =
64
BACKTRACE_LINES =
6

Instance Method Summary collapse

Methods inherited from Charming::Component

#captures_text?

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(error:, width: DEFAULT_WIDTH, root: Dir.pwd, theme: nil) ⇒ ErrorScreen

error is the rescued exception. width is the panel’s total width. root is the app root used to shorten backtrace paths (defaults to the working directory).



15
16
17
18
19
20
# File 'lib/charming/presentation/components/error_screen.rb', line 15

def initialize(error:, width: DEFAULT_WIDTH, root: Dir.pwd, theme: nil)
  super(theme: theme)
  @error = error
  @width = width
  @root = root
end

Instance Method Details

#renderObject

Renders the bordered error panel.



23
24
25
# File 'lib/charming/presentation/components/error_screen.rb', line 23

def render
  box(column(*sections, gap: 1), style: panel_style)
end