betty.serde.error module¶
Provide serialization error handling utilities.
- exception betty.serde.error.SerdeError[source]¶
Bases:
UserFacingError
,ValueError
A (de)serialization error.
- Parameters:
message (
betty.locale.Localizable
)
- __init__(message: betty.locale.Localizable)[source]¶
- Parameters:
message (
betty.locale.Localizable
)
- property contexts: tuple[Localizable, ...]¶
Get the human-readable contexts describing where the error occurred in the source data.
- localize(localizer: betty.locale.Localizer) str [source]¶
Localize
self
to a human-readable string.- Parameters:
localizer (
betty.locale.Localizer
)- Return type:
- raised(error_type: type[betty.serde.error.SerdeError]) bool [source]¶
Check if the error matches the given error type.
- Parameters:
error_type (
type
[betty.serde.error.SerdeError
])- Return type:
- with_context(*contexts: betty.locale.Localizable) Self [source]¶
Add a message describing the error’s context.
- Parameters:
contexts (
betty.locale.Localizable
)- Return type:
typing.Self
- exception betty.serde.error.SerdeErrorCollection[source]¶
Bases:
SerdeError
A collection of zero or more (de)serialization errors.
- Parameters:
errors (
list
[betty.serde.error.SerdeError
] |None
)
- __init__(errors: list[betty.serde.error.SerdeError] | None = None)[source]¶
- Parameters:
errors (
list
[betty.serde.error.SerdeError
] |None
)
- append(*errors: betty.serde.error.SerdeError) None [source]¶
Append errors to this collection.
- Parameters:
errors (
betty.serde.error.SerdeError
)- Return type:
- assert_valid() Iterator[Self] [source]¶
Assert that this collection contains no errors.
- Return type:
typing.Iterator
[typing.Self
]
- catch(*contexts: betty.locale.Localizable) Iterator[betty.serde.error.SerdeErrorCollection] [source]¶
Catch any errors raised within this context manager and add them to the collection.
- Return type:
- Returns:
A new collection that will only contain any newly raised errors.
- Parameters:
contexts (
betty.locale.Localizable
)
- localize(localizer: betty.locale.Localizer) str [source]¶
Localize
self
to a human-readable string.- Parameters:
localizer (
betty.locale.Localizer
)- Return type:
- raised(error_type: type[betty.serde.error.SerdeError]) bool [source]¶
Check if the error matches the given error type.
- Parameters:
error_type (
type
[betty.serde.error.SerdeError
])- Return type:
- with_context(*contexts: betty.locale.Localizable) Self [source]¶
Add a message describing the error’s context.
- Parameters:
contexts (
betty.locale.Localizable
)- Return type:
typing.Self