Skip to main content

laser_wire/
error.rs

1/// A codec, framing, or payload decode failure. Deterministic for a given
2/// input, so never retryable. The SDK maps it into its own error type, and
3/// ports surface it as-is.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum DecodeError {
7    #[error("encode: {0}")]
8    Encode(String),
9    #[error("decode: {0}")]
10    Decode(String),
11    #[error("no payload: {0}")]
12    MissingPayload(&'static str),
13    /// A `[len: u32 LE][bytes]` frame violated the framing contract (over the
14    /// frame cap, or a length prefix pointing past the cap).
15    #[error("frame: {0}")]
16    Frame(String),
17}
18
19/// Client-side validation rejected the input before any encode or round-trip
20/// (missing required builder fields, empty identifiers).
21#[derive(Debug, PartialEq, Eq, thiserror::Error)]
22#[error("{0}")]
23pub struct InvalidError(pub String);
24
25impl InvalidError {
26    /// A validation failure with this message.
27    pub fn new(message: impl Into<String>) -> Self {
28        Self(message.into())
29    }
30}