Module

server.debug_page

Self-contained debug error page renderer.

Renders rich error pages without depending on kida or any user template environment. Uses plain f-strings and string concatenation so that a broken template system cannot prevent error reporting.

The page renders:

  • Exception type and message
  • Traceback with source context, locals, and app-frame highlighting
  • Request context (method, path, headers, query, form, route)
  • Template error integration (kida source locations and suggestions)
  • Editor-clickable file:line links (via CHIRP_EDITOR env var)

Two output modes:

  • Full page: complete HTML document with dark theme
  • Fragment: compact HTML snippet for htmx partial responses

Functions

_editor_url 2 str | None
Build a clickable editor URL from CHIRP_EDITOR env var. Supports preset names …
def _editor_url(filepath: str, lineno: int) -> str | None

Build a clickable editor URL from CHIRP_EDITOR env var.

Supports preset names (vscode, cursor, sublime, textmate, idea, pycharm) or custom patterns with __FILE__ / __LINE__ placeholders.

ReturnsNone if CHIRP_EDITORis not set.

Parameters
Name Type Description
filepath str
lineno int
Returns
str | None
_is_app_frame 1 bool
True if the frame is from the application (not stdlib/site-packages).
def _is_app_frame(filename: str) -> bool
Parameters
Name Type Description
filename str
Returns
bool
_extract_frames 1 list[dict[str, Any]]
Walk a traceback and extract frame info with source context and locals.
def _extract_frames(tb: types.TracebackType | None) -> list[dict[str, Any]]
Parameters
Name Type Description
tb types.TracebackType | None
Returns
list[dict[str, Any]]
_extract_template_context 1 dict[str, Any] | None
Extract rich context from kida template exceptions. Returns a dict with templa…
def _extract_template_context(exc: BaseException) -> dict[str, Any] | None

Extract rich context from kida template exceptions.

Returns a dict with template-specific error info, or None if the exception is not a kida template error.

Parameters
Name Type Description
exc BaseException
Returns
dict[str, Any] | None
_extract_request_context 1 dict[str, Any]
Extract displayable request context from a chirp Request.
def _extract_request_context(request: Any) -> dict[str, Any]
Parameters
Name Type Description
request Any
Returns
dict[str, Any]
_esc 1 str
HTML-escape a string.
def _esc(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
_render_source_lines 2 str
Render source lines with error highlighting.
def _render_source_lines(source_lines: list[tuple[int, str]], error_lineno: int) -> str
Parameters
Name Type Description
source_lines list[tuple[int, str]]
error_lineno int
Returns
str
_render_locals 1 str
Render local variables panel.
def _render_locals(local_vars: dict[str, str]) -> str
Parameters
Name Type Description
local_vars dict[str, str]
Returns
str
_render_frame 1 str
Render a single traceback frame.
def _render_frame(frame: dict[str, Any]) -> str
Parameters
Name Type Description
frame dict[str, Any]
Returns
str
_render_template_panel 1 str
Render the kida template error panel.
def _render_template_panel(ctx: dict[str, Any]) -> str
Parameters
Name Type Description
ctx dict[str, Any]
Returns
str
_render_request_panel 1 str
Render request context panel.
def _render_request_panel(request: Any) -> str
Parameters
Name Type Description
request Any
Returns
str
render_debug_page 3 str
Render a rich debug error page.
def render_debug_page(exc: BaseException, request: Any, *, is_fragment: bool = False) -> str
Parameters
Name Type Description
exc BaseException

The exception that caused the error.

request Any

The chirp Request object.

is_fragment bool

If True, render a compact fragment instead of a full page.

Default:False
Returns
str