1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Error types for framing and envelope validation.
/// Frame decoder failure. The message mirrors the TypeScript decoder exactly
/// so both sides report the same text when a peer breaks the cap.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum FrameError {
/// A frame (across all its chunks) exceeded the configured limit.
#[error("IPC frame exceeded the 32 MB limit.")]
ExceededLimit,
}
/// Envelope validation failure (`isDaemonRequest` / `isBasicResponse`).
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ValidationError {
/// Frame carried a version this host does not speak.
#[error("Unsupported protocol version {actual}; this host speaks {expected}.")]
WrongVersion { expected: u32, actual: u32 },
/// `id` is empty or longer than 64 JS string length units.
#[error("Request id must be 1-64 characters, got {actual}.")]
InvalidIdLength { actual: usize },
/// `action` is empty or longer than 64 JS string length units.
#[error("Action must be 1-64 characters, got {actual}.")]
InvalidActionLength { actual: usize },
/// A response did not echo the requested version.
#[error("Response version {actual} does not echo the requested version {expected}.")]
ResponseVersionMismatch { expected: u32, actual: u32 },
/// A response carried neither the success nor the failure shape.
#[error("Response carries neither a result nor an error.")]
MalformedResponse,
/// A frame exceeded the JSON node or nesting budget before parsing.
#[error("IPC frame exceeded the JSON structure budget.")]
JsonBudget,
/// A payload string failed `requireString`: missing, empty, not a string,
/// or over the byte cap — one fixed message for all four.
#[error("{name} must be a non-empty string under {max_bytes} bytes.")]
PayloadString {
name: &'static str,
max_bytes: usize,
},
/// A payload number failed `requireInteger`: not a JS integer or outside
/// the inclusive range — one fixed message for every failure mode.
#[error("{name} must be an integer between {min} and {max}.")]
PayloadInteger {
name: &'static str,
min: u64,
max: u64,
},
}