Module

rendering.errors

Rich template error objects with line numbers, context, and suggestions.

Classes

TemplateErrorContext dataclass
Context around an error in a template.
0

Context around an error in a template.

Attributes

Name Type Description
template_name str
line_number int | None
column int | None
source_line str | None
surrounding_lines list[tuple[int, str]]
template_path Path | None
InclusionChain dataclass
Represents the template inclusion chain.
1

Represents the template inclusion chain.

Attributes

Name Type Description
entries list[tuple[str, int | None]]
Internal Methods 1
__str__
Format as readable chain.
0 str
def __str__(self) -> str

Format as readable chain.

Returns

str

TemplateRenderError dataclass
Rich template error with all debugging information. This replaces the simple string error messages…
6

Rich template error with all debugging information.

This replaces the simple string error messages with structured data that can be displayed beautifully and used for IDE integration.

Attributes

Name Type Description
error_type str
message str
template_context TemplateErrorContext
inclusion_chain InclusionChain | None
page_source Path | None
suggestion str | None
available_alternatives list[str]
search_paths list[Path] | None

Methods 1

from_jinja2_error classmethod
Extract rich error information from Jinja2 exception.
4 TemplateRenderError
def from_jinja2_error(cls, error: Exception, template_name: str, page_source: Path | None, template_engine: Any) -> TemplateRenderError

Extract rich error information from Jinja2 exception.

Parameters 4
error Exception

Jinja2 exception

template_name str

Template being rendered

page_source Path | None

Source content file (if applicable)

template_engine Any

Template engine instance

Returns

TemplateRenderError

Rich error object

Internal Methods 5
_classify_error staticmethod
Classify Jinja2 error type.
1 str
def _classify_error(error: Exception) -> str

Classify Jinja2 error type.

Parameters 1
error Exception
Returns

str

_extract_context staticmethod
Extract template context from error.
3 TemplateErrorContext
def _extract_context(error: Exception, template_name: str, template_engine: Any) -> TemplateErrorContext

Extract template context from error.

Parameters 3
error Exception
template_name str
template_engine Any
Returns

TemplateErrorContext

_build_inclusion_chain staticmethod
Build template inclusion chain from traceback.
2 InclusionChain | None
def _build_inclusion_chain(error: Exception, template_engine: Any) -> InclusionChain | None

Build template inclusion chain from traceback.

Parameters 2
error Exception
template_engine Any
Returns

InclusionChain | None

_generate_suggestion staticmethod
Generate helpful suggestion based on error.
3 str | None
def _generate_suggestion(error: Exception, error_type: str, template_engine: Any) -> str | None

Generate helpful suggestion based on error.

Parameters 3
error Exception
error_type str
template_engine Any
Returns

str | None

_find_alternatives staticmethod
Find alternative filters/variables that might work.
3 list[str]
def _find_alternatives(error: Exception, error_type: str, template_engine: Any) -> list[str]

Find alternative filters/variables that might work.

Parameters 3
error Exception
error_type str
template_engine Any
Returns

list[str]

Functions

display_template_error
Display a rich template error in the terminal.
2 None
def display_template_error(error: TemplateRenderError, use_color: bool = True) -> None

Display a rich template error in the terminal.

Parameters 2

Name Type Default Description
error TemplateRenderError

Rich error object

use_color bool True

Whether to use terminal colors

_display_template_error_rich
Display template error with rich formatting.
1 None
def _display_template_error_rich(error: TemplateRenderError) -> None

Display template error with rich formatting.

Parameters 1

Name Type Default Description
error TemplateRenderError
_generate_enhanced_suggestions
Generate context-aware suggestions for template errors.
1 list[str]
def _generate_enhanced_suggestions(error: TemplateRenderError) -> list[str]

Generate context-aware suggestions for template errors.

Parameters 1

Name Type Default Description
error TemplateRenderError

Returns

list[str]

_extract_variable_name
Extract variable name from undefined variable error.
1 str | None
def _extract_variable_name(error_message: str) -> str | None

Extract variable name from undefined variable error.

Parameters 1

Name Type Default Description
error_message str

Returns

str | None

_extract_filter_name
Extract filter name from filter error.
1 str | None
def _extract_filter_name(error_message: str) -> str | None

Extract filter name from filter error.

Parameters 1

Name Type Default Description
error_message str

Returns

str | None

_extract_dict_attribute
Extract attribute name from dict access error.
1 str | None
def _extract_dict_attribute(error_message: str) -> str | None

Extract attribute name from dict access error.

Parameters 1

Name Type Default Description
error_message str

Returns

str | None

_display_template_error_click
Fallback display using click (original implementation).
2 None
def _display_template_error_click(error: TemplateRenderError, use_color: bool = True) -> None

Fallback display using click (original implementation).

Parameters 2

Name Type Default Description
error TemplateRenderError
use_color bool True