pub struct UnicodeErrorData {
pub encoding: String,
pub object: UnicodeErrorObject,
pub start: usize,
pub end: usize,
pub reason: String,
}Expand description
Structured fields of a UnicodeDecodeError / UnicodeEncodeError,
mirroring CPython’s encoding / object / start / end / reason
exception attributes.
Monty exceptions are otherwise message-only; unicode errors additionally
carry these fields so host bindings (e.g. pydantic_monty) can construct
real UnicodeDecodeError / UnicodeEncodeError instances instead of
falling back to a plain ValueError. The payload is omitted when the
offending object is larger than UnicodeErrorData::MAX_OBJECT_LEN —
exceptions can be stored and copied outside the sandbox’s resource
tracker, so an unbounded payload would let huge inputs evade memory
limits. Sandboxed code never sees these fields (in-sandbox exceptions
expose only args).
Fields§
§encoding: StringThe codec name as CPython reports it, e.g. "utf-8", "ascii".
object: UnicodeErrorObjectThe full input that failed to encode/decode (str for encode errors,
bytes for decode errors), matching CPython’s exc.object.
start: usizeStart of the failing range: a character index for encode errors, a byte offset for decode errors.
end: usizeExclusive end of the failing range, in the same units as start.
reason: StringCPython’s reason wording, e.g. "ordinal not in range(128)".
Implementations§
Source§impl UnicodeErrorData
impl UnicodeErrorData
Sourcepub const MAX_OBJECT_LEN: usize
pub const MAX_OBJECT_LEN: usize
Payload size cap: unicode errors on objects larger than this carry no
structured data (hosts fall back to the message-only ValueError).
Exception payloads are copied into the host once they escape the worker,
so the cap bounds how much host memory a single raise can pin.
Sourcepub fn encode(
encoding: &str,
object: &str,
start: usize,
end: usize,
reason: &str,
) -> ExcData
pub fn encode( encoding: &str, object: &str, start: usize, end: usize, reason: &str, ) -> ExcData
Builds the payload for an encode error on object, or
ExcData::None when object exceeds Self::MAX_OBJECT_LEN.
Sourcepub fn decode(
encoding: &str,
object: &[u8],
start: usize,
end: usize,
reason: &str,
) -> ExcData
pub fn decode( encoding: &str, object: &[u8], start: usize, end: usize, reason: &str, ) -> ExcData
Builds the payload for a decode error on object, or
ExcData::None when object exceeds Self::MAX_OBJECT_LEN.
Public so monty-fs can build the payload for text-mode file reads.
Trait Implementations§
Source§impl Clone for UnicodeErrorData
impl Clone for UnicodeErrorData
Source§fn clone(&self) -> UnicodeErrorData
fn clone(&self) -> UnicodeErrorData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more