Error¶
error
¶
Fundamental error class for the Building Blocks framework.
Defines the base Error type that all structured errors inherit from.
Error
¶
Bases: Exception, Debuggable
Base class for all structured errors that can be raised like standard Exceptions.
Example
Source code in src/forging_blocks/foundation/errors/base/error.py
message: ErrorMessage
property
¶
Structured error message.
metadata: ErrorMetadata[MetadataValueType]
property
¶
Structured metadata with additional context.
context: dict[str, MetadataValueType]
property
¶
Shortcut for accessing the metadata context.
__init__(message: ErrorMessage, metadata: ErrorMetadata[MetadataValueType] | None = None) -> None
¶
Initialise the error with a structured message and optional metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
ErrorMessage
|
The structured error message describing what went wrong. |
required |
metadata
|
ErrorMetadata[MetadataValueType] | None
|
Optional structured metadata with additional diagnostic |
None
|
Source code in src/forging_blocks/foundation/errors/base/error.py
from_string(text: str, metadata: ErrorMetadata[MetadataValueType] | None = None) -> Self
classmethod
¶
Create an error from a plain message string.
Convenience factory that wraps text in an ErrorMessage
and passes it to the constructor. All Error subclasses
inherit this method so callers can raise errors without
manually constructing ErrorMessage instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The raw error message text. |
required |
metadata
|
ErrorMetadata[MetadataValueType] | None
|
Optional structured metadata with diagnostic context. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A new error instance. |
Example
Source code in src/forging_blocks/foundation/errors/base/error.py
as_debug_string() -> str
¶
Return a detailed, multi-line string for debugging.