Module

_debug

Development error pages with rich tracebacks.

Provides beautiful, detailed error pages for debugging during development. In production mode, returns simple 500 errors without exposing internals.

Features:

  • Full traceback with source code context
  • Syntax highlighting via Rosettes (if available)
  • Local variables inspection
  • Request details (method, path, headers)
  • Safe for production (only enabled in debug mode)

Security:

  • Only active when debug=True in config
  • Never exposes source code or internals in production
  • Sanitizes sensitive data from error output

Functions

is_rosettes_available 0 bool
Check if Rosettes syntax highlighter is available.
def is_rosettes_available() -> bool
Returns
bool
format_exception_html 6 str
Format an exception as a rich HTML error page.
def format_exception_html(exc_type: type[BaseException], exc_value: BaseException, exc_tb: Any, *, request_method: str = 'GET', request_path: str = '/', request_headers: list[tuple[bytes, bytes]] | None = None) -> str
Parameters
Name Type Description
exc_type type[BaseException]

Exception class.

exc_value BaseException

Exception instance.

exc_tb Any

Traceback object.

request_method str

HTTP method for context.

Default:'GET'
request_path str

Request path for context.

Default:'/'
request_headers list[tuple[bytes, bytes]] | None

Request headers for context.

Default:None
Returns
str
_extract_frames 1 list[dict[str, Any]]
Extract frame information from a traceback.
def _extract_frames(tb: Any) -> list[dict[str, Any]]
Parameters
Name Type Description
tb Any

Traceback object.

Returns
list[dict[str, Any]]
_get_source_context 3 list[tuple[int, str]]
Get source code lines around the given line number.
def _get_source_context(filename: str, lineno: int, context: int = 5) -> list[tuple[int, str]]
Parameters
Name Type Description
filename str

Path to source file.

lineno int

Line number (1-indexed).

context int

Number of lines before/after to include.

Default:5
Returns
list[tuple[int, str]]
_sanitize_locals 1 dict[str, str]
Sanitize local variables for safe display. Removes sensitive data and formats …
def _sanitize_locals(local_vars: dict[str, Any]) -> dict[str, str]

Sanitize local variables for safe display.

Removes sensitive data and formats values for display.

Parameters
Name Type Description
local_vars dict[str, Any]

Dictionary of local variables.

Returns
dict[str, str]
_render_header 4 str
Render the HTML header with exception details.
def _render_header(exc_type: type[BaseException], exc_value: BaseException, method: str, path: str) -> str
Parameters
Name Type Description
exc_type type[BaseException]
exc_value BaseException
method str
path str
Returns
str
_render_frame 1 str
Render a single traceback frame as HTML.
def _render_frame(frame_info: dict[str, Any]) -> str
Parameters
Name Type Description
frame_info dict[str, Any]
Returns
str
_render_request_details 3 str
Render request details section.
def _render_request_details(method: str, path: str, headers: list[tuple[bytes, bytes]]) -> str
Parameters
Name Type Description
method str
path str
headers list[tuple[bytes, bytes]]
Returns
str
_render_footer 0 str
Render HTML footer.
def _render_footer() -> str
Returns
str
create_debug_error_response 6 tuple[int, list[tuple[by…
Create an HTTP error response with rich traceback.
def create_debug_error_response(exc_type: type[BaseException], exc_value: BaseException, exc_tb: Any, *, request_method: str = 'GET', request_path: str = '/', request_headers: list[tuple[bytes, bytes]] | None = None) -> tuple[int, list[tuple[bytes, bytes]], bytes]
Parameters
Name Type Description
exc_type type[BaseException]

Exception class.

exc_value BaseException

Exception instance.

exc_tb Any

Traceback object.

request_method str

HTTP method.

Default:'GET'
request_path str

Request path.

Default:'/'
request_headers list[tuple[bytes, bytes]] | None

Request headers.

Default:None
Returns
tuple[int, list[tuple[bytes, bytes]], bytes]
create_production_error_response 0 tuple[int, list[tuple[by…
Create a simple 500 error response for production.
def create_production_error_response() -> tuple[int, list[tuple[bytes, bytes]], bytes]
Returns
tuple[int, list[tuple[bytes, bytes]], bytes]