binobj.errors module¶
Errors for the binobj package.
- exception ArraySizeError(*, field: Field[Any], n_expected: int, n_given: int | None = None)¶
Bases:
SerializationError
The array can’t be serialized because there are too many or too few items.
- exception ConfigurationError(message: str | None = None, *, field: str | Field[Any] | None = None, struct: str | Struct | Type[Struct] | None = None, obj: Any = None)¶
Bases:
Error
A field, struct, or other object was misconfigured.
At least one of the
field
,struct
, orobj
keyword arguments must be passed to the constructor.- Parameters:
message (str) – Optional. A description of what’s wrong. If not given, a generic error message will be chosen depending on which of the
field
,struct
, orobj
keyword arguments is passed.field – The misconfigured
Field
or its name.struct – The misconfigured
Struct
or its name.obj – If the misconfigured object is neither a field nor a struct, pass it or its name here.
- Raises:
ValueError – None of the
field
,struct
, orobj
keyword arguments were passed.
New in version 0.3.0: The
struct
andobj
arguments.
- exception DeserializationError(message: str | None = None, *, field: Field[Any] | None = None, data: bytes | None = None, offset: int | None = None)¶
Bases:
Error
An error occurred while deserializing data.
- exception Error(message: str | None = None, *args: Any)¶
Bases:
Exception
Base class for all binobj errors.
Do not throw this exception directly.
- exception ExtraneousDataError(message: str | None = None, *, field: Field[Any] | None = None, data: bytes | None = None, offset: int | None = None)¶
Bases:
DeserializationError
Extra bytes were found at the end of the input after deserialization.
- exception FieldRedefinedError(*, struct: str, field: str | Field[Any])¶
Bases:
ConfigurationError
A struct has a field already defined in a parent class.
- Parameters:
New in version 0.3.0.
- exception FieldReferenceError(message: str | None = None, *, field: str)¶
Bases:
Error
An error occurred while computing a field reference.
- exception IllegalOperationError(message: str | None = None, *args: Any)¶
Bases:
Error
The attempted operation is disallowed.
New in version 0.4.1.
- exception ImmutableFieldError(*, field: Field[Any] | None = None)¶
Bases:
IllegalOperationError
Cannot assign to an immutable or computed field.
- Parameters:
field (Field) – The field an attempt was made to be assigned to.
New in version 0.4.1.
New in version 0.6.1: The
field
argument.
- exception MissingRequiredValueError(*, field: str | Field[Any])¶
Bases:
SerializationError
No value was passed for a required field.
- Parameters:
field – The missing field, or its name.
- exception MultipleInheritanceError(message: str | None = None, *, field: str | Field[Any] | None = None, struct: str | Struct | Type[Struct] | None = None, obj: Any = None)¶
Bases:
ConfigurationError
A Struct can’t inherit from more than one Struct.
This restriction is in place because the field ordering could be non-intuitive given Python’s MRO.
New in version 0.3.0.
- exception SerializationError(message: str | None = None, *, struct: Struct | None = None, field: str | Field[Any] | None = None, value: T | None = None)¶
Bases:
Error
An error occurred while serializing data.
- exception UndefinedSizeError(*, field: str | Field[Any])¶
Bases:
ConfigurationError
The size of the field couldn’t be determined, possibly due to misconfiguration.
- Parameters:
field – The
Field
that’s missing its size, or the name of that field.
New in version 0.3.1.
- exception UnexpectedEOFError(*, field: Field[Any] | None, size: int, offset: int)¶
Bases:
DeserializationError
Hit EOF while reading, but expected more data.
- exception UnexpectedValueError(*, struct: Struct, name: str | Iterable[str])¶
Bases:
SerializationError
The data to dump has unexpected fields.
- exception UnserializableValueError(*, field: Field[T], value: T | None, reason: str | None = None)¶
Bases:
SerializationError
The value couldn’t be serialized.
- exception ValidationError(message: str | None = None, *, field: Field[T], value: T | None)¶
Bases:
Error
Validation failed for one or more fields.
- exception ValueSizeError(*, field: Field[Any], value: Any)¶
Bases:
UnserializableValueError
The value can’t be serialized because it doesn’t fit into the field.
- Parameters:
field (Field) – The field that failed to serialize the given value.
value – The value that’s the wrong size.