Classes
TemplateErrorContext
dataclass
Context around an error in a template.
TemplateErrorContext
dataclass 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.
InclusionChain
dataclass Represents the template inclusion chain.
Attributes
| Name | Type | Description |
|---|---|---|
entries |
list[tuple[str, int | None]] |
Internal Methods 1
__str__
Format as readable chain.
__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…
TemplateRenderError
dataclass 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.
from_jinja2_error
classmethod 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
Rich error objectTemplateRenderError
—
Internal Methods 5
_classify_error
staticmethod
Classify Jinja2 error type.
_classify_error
staticmethod def _classify_error(error: Exception) -> str
Classify Jinja2 error type.
Parameters 1
error |
Exception |
Returns
str
_extract_context
staticmethod
Extract template context from error.
_extract_context
staticmethod 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.
_build_inclusion_chain
staticmethod 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.
_generate_suggestion
staticmethod 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.
_find_alternatives
staticmethod 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.
display_template_error
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.
_display_template_error_rich
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.
_generate_enhanced_suggestions
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.
_extract_variable_name
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.
_extract_filter_name
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.
_extract_dict_attribute
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).
_display_template_error_click
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 |