gufo.err.abc.formatter¶
BaseFormatter class.
BaseFormatter
¶
Bases: ABC
Abstract base class for formatters.
Formatters process ErrorInfo instances and produces human-readable output.
All formatters must implement iter_format
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
primary_char |
str
|
Caret primary char. |
DEFAULT_PRIMARY_CHAR
|
secondary_char |
str
|
Caret secondary char. |
DEFAULT_SECONDARY_CHAR
|
format(err)
¶
Format ErrorInfo to human-readable string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
err |
ErrorInfo
|
ErrorInfo instance |
required |
Returns:
Type | Description |
---|---|
str
|
Human-readable output. |
get_caret(line, pos, indent, dedent=0)
¶
Generate caret for code position.
Carret has a format:
<spaces><primary chars...><secondary chars...><primary chars...>
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line |
str
|
Current unstripped line of code |
required |
pos |
CodePosition
|
CodePositio |
required |
indent |
int
|
Add |
required |
dedent |
int
|
Remove |
0
|
get_exception_summary(x)
staticmethod
¶
Format exception to summary string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
BaseException
|
Exception instance |
required |
Returns:
Type | Description |
---|---|
str
|
Formatted string |
iter_format(err)
abstractmethod
¶
Iterator yielding human-redable lines.
Process ErrorInfo instance and yield humar-readable lines one-by-one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
err |
ErrorInfo
|
ErrorInfo instance |
required |
Returns:
Type | Description |
---|---|
Iterable[str]
|
Iterator yieldig formatted lines. |
iter_stack(err)
¶
traceback_message()
¶
Get proper traceback message.
Returns:
Type | Description |
---|---|
str
|
String like "Traceback (most resent call last):" |