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
49
50
51
52
53
54
55
56
57
58
59
//! Typed error hierarchy for the bridge.
/// Errors from the worker bridge.
#[derive(Debug, thiserror::Error)]
pub enum BridgeError {
/// `Worker::new()` failed (invalid script URL, CSP, etc.).
#[error("worker spawn failed: {0}")]
Spawn(String),
/// Serialisation of a command or event failed.
#[error("serialisation failed: {0}")]
Serialisation(String),
/// `postMessage` rejected by the browser.
#[error("postMessage failed: {0}")]
PostMessage(String),
/// Script-level error (wrong URL, CSP, syntax error in worker script).
/// Not automatically recoverable — the script itself is broken.
#[error("worker script error: {0}")]
WorkerError(String),
/// Worker process crashed (WASM panic, OOM, unreachable trap).
/// A Supervisor should attempt respawn.
#[error("worker crashed")]
WorkerCrashed,
/// The worker handle has been terminated.
#[error("bridge terminated")]
Terminated,
/// The event channel has been closed (receiver dropped).
#[error("event channel closed")]
ChannelClosed,
/// The command channel is full — the worker cannot accept more commands.
#[error("command channel full")]
ChannelFull,
/// Builder configuration is invalid.
#[error("invalid configuration: {0}")]
InvalidConfig(String),
}
impl BridgeError {
/// True if the error indicates the worker process died unexpectedly
/// and respawn may succeed.
pub fn is_crash(&self) -> bool {
matches!(self, Self::WorkerCrashed)
}
/// True if the error is permanent and respawn will not help.
pub fn is_permanent(&self) -> bool {
matches!(
self,
Self::Spawn(_) | Self::WorkerError(_) | Self::InvalidConfig(_)
)
}
}