Skip to main content

dig_rpc_protocol/
error.rs

1//! The canonical DIG-node RPC error taxonomy.
2//!
3//! This module is the **single definition point** for every error code the DIG
4//! node RPC surface emits, the canonical [`RpcError`] envelope
5//! (`{code, message, data:{code, origin}}`), and the one constructor helper both
6//! node implementations call so every error carries a machine-branchable
7//! `data.code` and `data.origin`.
8//!
9//! # The code set
10//!
11//! Standard JSON-RPC 2.0 codes plus the DIG protocol-specific codes. The numeric
12//! values are a **published wire contract** and never change once assigned.
13//!
14//! | Code | Variant | Origin | Meaning |
15//! |---|---|---|---|
16//! | `-32700` | [`ParseError`](ErrorCode::ParseError) | Node | request body is not valid JSON |
17//! | `-32600` | [`InvalidRequest`](ErrorCode::InvalidRequest) | Node | not a valid Request object |
18//! | `-32601` | [`MethodNotFound`](ErrorCode::MethodNotFound) | Node | method not implemented |
19//! | `-32602` | [`InvalidParams`](ErrorCode::InvalidParams) | Node | missing/malformed params |
20//! | `-32603` | [`InternalError`](ErrorCode::InternalError) | Node | well-formed call failed |
21//! | `-32000` | [`ServerError`](ErrorCode::ServerError) | Node | generic server error |
22//! | `-32004` | [`ResourceUnavailable`](ErrorCode::ResourceUnavailable) | Node | resource not available at the requested root (genuine infra miss) |
23//! | `-32005` | [`RootNotAnchored`](ErrorCode::RootNotAnchored) | Node | requested/served root is not the chain-anchored root (fail-closed pin) |
24//! | `-32006` | [`PeerUnreachable`](ErrorCode::PeerUnreachable) | Node | no NAT-traversal strategy reached the peer |
25//! | `-32007` | [`RangeNotSatisfiable`](ErrorCode::RangeNotSatisfiable) | Node | byte range lies outside the resource |
26//! | `-32008` | [`ContentRedirect`](ErrorCode::ContentRedirect) | Node | content held elsewhere — `data.redirect` names holders |
27//! | `-32009` | [`RangeMetadataUnrepresentable`](ErrorCode::RangeMetadataUnrepresentable) | Node | the resource's own range metadata cannot fit a conforming frame, so this holder can NEVER serve the range |
28//! | `-32010` | [`UpstreamError`](ErrorCode::UpstreamError) | Upstream | an upstream/proxy fetch failed |
29//! | `-32011` | [`StageInvalidInput`](ErrorCode::StageInvalidInput) | Node | `dig.stage`: dir unreadable / walk budget exceeded |
30//! | `-32012` | [`StageNoFiles`](ErrorCode::StageNoFiles) | Node | `dig.stage`: no files to compile |
31//! | `-32013` | [`StageOverCap`](ErrorCode::StageOverCap) | Node | `dig.stage`: input exceeds the store cap |
32//! | `-32014` | [`StageCompileFailed`](ErrorCode::StageCompileFailed) | Node | `dig.stage`: compile / IO failure |
33//! | `-32020` | [`OnionCircuitUnavailable`](ErrorCode::OnionCircuitUnavailable) | Onion | private read could not build/keep a circuit |
34//! | `-32021` | [`PrivacyRequiresLocalNode`](ErrorCode::PrivacyRequiresLocalNode) | Onion | privacy mode requires the caller be a local originator |
35//! | `-32022` | [`OnionHopsOutOfRange`](ErrorCode::OnionHopsOutOfRange) | Onion | requested hop count outside `[2, 5]` |
36//! | `-32030` | [`Unauthorized`](ErrorCode::Unauthorized) | Control | control-plane call is not authorized |
37//! | `-32031` | [`NotSupported`](ErrorCode::NotSupported) | Control | control-plane method not supported here |
38//! | `-32032` | [`ControlError`](ErrorCode::ControlError) | Control | control-plane runtime error |
39//!
40//! ## The `-32020..-32022` collision, resolved
41//!
42//! The published normative protocol (docs.dig.net) assigns `-32020/-32021/-32022`
43//! to the **onion** (private-retrieval) failures. Those keep their numbers. The
44//! control-plane errors that previously squatted the same values are renumbered
45//! to `-32030/-32031/-32032`.
46
47use serde::{Deserialize, Serialize};
48use serde_repr::{Deserialize_repr, Serialize_repr};
49
50/// A canonical DIG-node RPC error code.
51///
52/// Serializes as a bare integer (via `serde_repr`), spec-compliant for
53/// `error.code`. `#[non_exhaustive]` so adding a code in a minor release is
54/// additive; downstream matches must use `_ => …`.
55#[repr(i32)]
56#[non_exhaustive]
57#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq, Hash)]
58pub enum ErrorCode {
59    // ---- Standard JSON-RPC 2.0 ----
60    /// Invalid JSON was received by the server.
61    ParseError = -32700,
62    /// The JSON sent is not a valid Request object.
63    InvalidRequest = -32600,
64    /// The method does not exist / is not available.
65    MethodNotFound = -32601,
66    /// Invalid method parameter(s).
67    InvalidParams = -32602,
68    /// The node failed to satisfy a well-formed call (network profile).
69    InternalError = -32603,
70
71    // ---- DIG protocol-specific (implementation-defined server range) ----
72    /// Generic server error (config write failure, file I/O, chain read failure).
73    ServerError = -32000,
74    /// Resource not available at the requested root — a genuine infrastructure
75    /// miss (absent module, bad magic, oversize, a trap, an undecodable
76    /// envelope). Distinct from a content miss, which is an indistinguishable
77    /// decoy and is never an error.
78    ResourceUnavailable = -32004,
79    /// The requested or served generation is not the store's current on-chain
80    /// root. The read path pins to the CHIP-0035 singleton's on-chain root and
81    /// fails closed rather than serving an unverified generation.
82    RootNotAnchored = -32005,
83    /// No connection to the named peer could be established — every
84    /// NAT-traversal strategy failed, or the peer is not on this network.
85    PeerUnreachable = -32006,
86    /// The requested byte range lies outside the resource (`offset >=
87    /// total_length`) or is otherwise unsatisfiable.
88    RangeNotSatisfiable = -32007,
89    /// This node does not hold the content but located peers that do.
90    /// `data.redirect` names the holders + the redirect budget.
91    ContentRedirect = -32008,
92    /// `dig.fetchRange`: the resource's own range metadata cannot be represented
93    /// in a conforming frame at all, so this holder can NEVER serve the range.
94    ///
95    /// A resource whose `chunk_lens` layout or `inclusion_proof` exceeds the
96    /// per-frame bounds has no conforming first frame, even with a paged prologue.
97    /// That is a permanent property of the resource, not a transient condition, so
98    /// it needs its own code: a client that could not tell it from an ordinary
99    /// transport failure would keep retrying a holder that cannot succeed, and would
100    /// retry every other holder of the same resource for the same reason.
101    RangeMetadataUnrepresentable = -32009,
102    /// An upstream/proxy fetch (e.g. `rpc.dig.net`) failed. Distinct from the
103    /// generic [`ServerError`](ErrorCode::ServerError) so a client can tell an
104    /// upstream fault from a local one.
105    UpstreamError = -32010,
106    /// `dig.stage`: the input directory is unreadable, or the bounded walk
107    /// exceeded its byte / file-count / depth budget.
108    StageInvalidInput = -32011,
109    /// `dig.stage`: the input directory contained no files to compile.
110    StageNoFiles = -32012,
111    /// `dig.stage`: the input exceeds the per-store size cap.
112    StageOverCap = -32013,
113    /// `dig.stage`: compiling the capsule failed (CLVM/IO error).
114    StageCompileFailed = -32014,
115
116    // ---- Onion / private retrieval (published normative — KEEP) ----
117    /// A `mode:"privacy"` read could not be served privately (no circuit could
118    /// be built, or one died mid-fetch). The node fails closed rather than
119    /// downgrading — a silent downgrade would deanonymize the reader.
120    OnionCircuitUnavailable = -32020,
121    /// `mode:"privacy"` was requested but the caller is not the node's own
122    /// trusted local originator. Privacy requires a local DIG node.
123    PrivacyRequiresLocalNode = -32021,
124    /// The requested `privacy.hops` (circuit length) is outside `[2, 5]`.
125    OnionHopsOutOfRange = -32022,
126
127    // ---- Control plane (loopback-only; renumbered off the onion codes) ----
128    /// The control-plane call is not authorized (loopback / token gate failed).
129    Unauthorized = -32030,
130    /// The control-plane method is recognized but not supported on this node.
131    NotSupported = -32031,
132    /// A control-plane runtime error (pin registry, sync trigger, config write).
133    ControlError = -32032,
134}
135
136impl ErrorCode {
137    /// The raw integer wire code.
138    pub const fn code(self) -> i32 {
139        self as i32
140    }
141
142    /// The stable `UPPER_SNAKE_CASE` machine identifier carried in `data.code`.
143    ///
144    /// This is the branch key an agent keys on; it never changes once assigned.
145    pub const fn machine_code(self) -> &'static str {
146        match self {
147            ErrorCode::ParseError => "PARSE_ERROR",
148            ErrorCode::InvalidRequest => "INVALID_REQUEST",
149            ErrorCode::MethodNotFound => "METHOD_NOT_FOUND",
150            ErrorCode::InvalidParams => "INVALID_PARAMS",
151            ErrorCode::InternalError => "INTERNAL_ERROR",
152            ErrorCode::ServerError => "SERVER_ERROR",
153            ErrorCode::ResourceUnavailable => "RESOURCE_UNAVAILABLE",
154            ErrorCode::RootNotAnchored => "ROOT_NOT_ANCHORED",
155            ErrorCode::PeerUnreachable => "PEER_UNREACHABLE",
156            ErrorCode::RangeNotSatisfiable => "RANGE_NOT_SATISFIABLE",
157            ErrorCode::ContentRedirect => "CONTENT_REDIRECT",
158            ErrorCode::RangeMetadataUnrepresentable => "RANGE_METADATA_UNREPRESENTABLE",
159            ErrorCode::UpstreamError => "UPSTREAM_ERROR",
160            ErrorCode::StageInvalidInput => "STAGE_INVALID_INPUT",
161            ErrorCode::StageNoFiles => "STAGE_NO_FILES",
162            ErrorCode::StageOverCap => "STAGE_OVER_CAP",
163            ErrorCode::StageCompileFailed => "STAGE_COMPILE_FAILED",
164            ErrorCode::OnionCircuitUnavailable => "ONION_CIRCUIT_UNAVAILABLE",
165            ErrorCode::PrivacyRequiresLocalNode => "PRIVACY_REQUIRES_LOCAL_NODE",
166            ErrorCode::OnionHopsOutOfRange => "ONION_HOPS_OUT_OF_RANGE",
167            ErrorCode::Unauthorized => "UNAUTHORIZED",
168            ErrorCode::NotSupported => "NOT_SUPPORTED",
169            ErrorCode::ControlError => "CONTROL_ERROR",
170        }
171    }
172
173    /// The default human-readable summary for this code (used when a caller does
174    /// not supply a more specific message).
175    pub const fn default_message(self) -> &'static str {
176        match self {
177            ErrorCode::ParseError => "Parse error",
178            ErrorCode::InvalidRequest => "Invalid request",
179            ErrorCode::MethodNotFound => "Method not found",
180            ErrorCode::InvalidParams => "Invalid params",
181            ErrorCode::InternalError => "Internal error",
182            ErrorCode::ServerError => "Server error",
183            ErrorCode::ResourceUnavailable => "Resource not available at the requested root",
184            ErrorCode::RootNotAnchored => "Root not chain-anchored",
185            ErrorCode::PeerUnreachable => "Peer unreachable",
186            ErrorCode::RangeNotSatisfiable => "Range not satisfiable",
187            ErrorCode::ContentRedirect => "Content held elsewhere — redirect",
188            ErrorCode::RangeMetadataUnrepresentable => {
189                "Range metadata cannot be represented in a conforming frame"
190            }
191            ErrorCode::UpstreamError => "Upstream error",
192            ErrorCode::StageInvalidInput => "Stage input directory not readable",
193            ErrorCode::StageNoFiles => "Stage input contained no files",
194            ErrorCode::StageOverCap => "Stage input over the store cap",
195            ErrorCode::StageCompileFailed => "Stage compile failed",
196            ErrorCode::OnionCircuitUnavailable => "Onion circuit unavailable",
197            ErrorCode::PrivacyRequiresLocalNode => "Privacy requires a local node",
198            ErrorCode::OnionHopsOutOfRange => "Onion hop count out of range",
199            ErrorCode::Unauthorized => "Unauthorized",
200            ErrorCode::NotSupported => "Not supported",
201            ErrorCode::ControlError => "Control-plane error",
202        }
203    }
204
205    /// The natural [`ErrorOrigin`] for this code (which subsystem the failure
206    /// arose in). A caller may override it — a `ResourceUnavailable` bubbled up
207    /// from an upstream proxy can be tagged [`ErrorOrigin::Upstream`].
208    pub const fn default_origin(self) -> ErrorOrigin {
209        match self {
210            ErrorCode::UpstreamError => ErrorOrigin::Upstream,
211            ErrorCode::OnionCircuitUnavailable
212            | ErrorCode::PrivacyRequiresLocalNode
213            | ErrorCode::OnionHopsOutOfRange => ErrorOrigin::Onion,
214            ErrorCode::Unauthorized | ErrorCode::NotSupported | ErrorCode::ControlError => {
215                ErrorOrigin::Control
216            }
217            ErrorCode::PeerUnreachable => ErrorOrigin::Peer,
218            _ => ErrorOrigin::Node,
219        }
220    }
221
222    /// Whether this variant is in the JSON-RPC-reserved range
223    /// (`-32768..=-32000`).
224    pub const fn is_jsonrpc_reserved(self) -> bool {
225        let c = self.code();
226        c >= -32768 && c <= -32000
227    }
228
229    /// Every code, in wire order. Drives the OpenRPC error catalogue and the
230    /// exhaustiveness conformance test — a new variant must be added here.
231    pub const ALL: &'static [ErrorCode] = &[
232        ErrorCode::ParseError,
233        ErrorCode::InvalidRequest,
234        ErrorCode::MethodNotFound,
235        ErrorCode::InvalidParams,
236        ErrorCode::InternalError,
237        ErrorCode::ServerError,
238        ErrorCode::ResourceUnavailable,
239        ErrorCode::RootNotAnchored,
240        ErrorCode::PeerUnreachable,
241        ErrorCode::RangeNotSatisfiable,
242        ErrorCode::ContentRedirect,
243        ErrorCode::RangeMetadataUnrepresentable,
244        ErrorCode::UpstreamError,
245        ErrorCode::StageInvalidInput,
246        ErrorCode::StageNoFiles,
247        ErrorCode::StageOverCap,
248        ErrorCode::StageCompileFailed,
249        ErrorCode::OnionCircuitUnavailable,
250        ErrorCode::PrivacyRequiresLocalNode,
251        ErrorCode::OnionHopsOutOfRange,
252        ErrorCode::Unauthorized,
253        ErrorCode::NotSupported,
254        ErrorCode::ControlError,
255    ];
256}
257
258/// The subsystem a failure arose in — carried in `data.origin` so a client can
259/// route the error (retry upstream, rebuild a circuit, re-auth the control
260/// plane) without parsing the message.
261#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
262#[serde(rename_all = "lowercase")]
263pub enum ErrorOrigin {
264    /// The node's own read/serve path.
265    Node,
266    /// The peer-network layer (discovery / availability / range serving).
267    Peer,
268    /// An upstream fetch (`rpc.dig.net` proxy / whole-store sync).
269    Upstream,
270    /// The onion (private-retrieval) layer.
271    Onion,
272    /// The loopback control plane.
273    Control,
274}
275
276/// Structured error context carried in `error.data`.
277///
278/// The canonical DIG envelope always carries `data.code` (the
279/// [`UPPER_SNAKE_CASE`](ErrorCode::machine_code) machine identifier) and
280/// `data.origin`. `redirect` is present only on
281/// [`ContentRedirect`](ErrorCode::ContentRedirect); `extra` carries any
282/// method-specific fields verbatim (flattened onto `data`).
283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
284pub struct ErrorData {
285    /// The stable `UPPER_SNAKE_CASE` machine code (mirrors the numeric `code`).
286    pub code: String,
287    /// The subsystem the failure arose in.
288    pub origin: ErrorOrigin,
289    /// The redirect payload — present only on `CONTENT_REDIRECT`.
290    #[serde(skip_serializing_if = "Option::is_none", default)]
291    pub redirect: Option<crate::types::RedirectInfo>,
292    /// Any additional method-specific fields, flattened onto `data`.
293    #[serde(flatten, default, skip_serializing_if = "serde_json::Map::is_empty")]
294    pub extra: serde_json::Map<String, serde_json::Value>,
295}
296
297/// The canonical DIG-node RPC error object: `{code, message, data:{code, origin}}`.
298///
299/// Build one with [`RpcError::new`] (or the code-specific helpers) so the numeric
300/// code, the `data.code` machine string, and the origin can never drift apart.
301#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
302pub struct RpcError {
303    /// The numeric wire code.
304    pub code: ErrorCode,
305    /// A human-readable message. May be refined over time; `data.code` is the
306    /// stable branch key.
307    pub message: String,
308    /// Structured, machine-branchable context.
309    pub data: ErrorData,
310}
311
312impl RpcError {
313    /// The single constructor: mint the canonical envelope from a code, a
314    /// message, and an origin. `data.code` is derived from `code` so the two
315    /// can never disagree.
316    pub fn new(code: ErrorCode, message: impl Into<String>, origin: ErrorOrigin) -> Self {
317        Self {
318            code,
319            message: message.into(),
320            data: ErrorData {
321                code: code.machine_code().to_string(),
322                origin,
323                redirect: None,
324                extra: serde_json::Map::new(),
325            },
326        }
327    }
328
329    /// Mint an error using the code's [default origin](ErrorCode::default_origin).
330    pub fn of(code: ErrorCode, message: impl Into<String>) -> Self {
331        Self::new(code, message, code.default_origin())
332    }
333
334    /// Mint an error using both the code's default origin and its
335    /// [default message](ErrorCode::default_message).
336    pub fn code_only(code: ErrorCode) -> Self {
337        Self::new(code, code.default_message(), code.default_origin())
338    }
339
340    /// Attach a [`RedirectInfo`](crate::types::RedirectInfo) payload (for
341    /// [`ContentRedirect`](ErrorCode::ContentRedirect)).
342    pub fn with_redirect(mut self, redirect: crate::types::RedirectInfo) -> Self {
343        self.data.redirect = Some(redirect);
344        self
345    }
346
347    /// Attach one extra `data` field (flattened onto `data`).
348    pub fn with_extra(mut self, key: impl Into<String>, value: serde_json::Value) -> Self {
349        self.data.extra.insert(key.into(), value);
350        self
351    }
352}
353
354impl std::fmt::Display for RpcError {
355    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
356        write!(f, "[{}] {}", self.code.machine_code(), self.message)
357    }
358}
359
360impl std::error::Error for RpcError {}
361
362#[cfg(test)]
363mod tests {
364    use super::*;
365
366    /// **Proves:** every numeric code is pinned to its published wire value.
367    /// **Catches:** a reorder/renumber, or a lost `#[repr(i32)]`.
368    #[test]
369    fn numeric_values_pinned() {
370        assert_eq!(ErrorCode::ParseError.code(), -32700);
371        assert_eq!(ErrorCode::InvalidRequest.code(), -32600);
372        assert_eq!(ErrorCode::MethodNotFound.code(), -32601);
373        assert_eq!(ErrorCode::InvalidParams.code(), -32602);
374        assert_eq!(ErrorCode::InternalError.code(), -32603);
375        assert_eq!(ErrorCode::ServerError.code(), -32000);
376        assert_eq!(ErrorCode::ResourceUnavailable.code(), -32004);
377        assert_eq!(ErrorCode::RootNotAnchored.code(), -32005);
378        assert_eq!(ErrorCode::PeerUnreachable.code(), -32006);
379        assert_eq!(ErrorCode::RangeNotSatisfiable.code(), -32007);
380        assert_eq!(ErrorCode::ContentRedirect.code(), -32008);
381        assert_eq!(ErrorCode::UpstreamError.code(), -32010);
382        assert_eq!(ErrorCode::StageInvalidInput.code(), -32011);
383        assert_eq!(ErrorCode::StageNoFiles.code(), -32012);
384        assert_eq!(ErrorCode::StageOverCap.code(), -32013);
385        assert_eq!(ErrorCode::StageCompileFailed.code(), -32014);
386        assert_eq!(ErrorCode::OnionCircuitUnavailable.code(), -32020);
387        assert_eq!(ErrorCode::PrivacyRequiresLocalNode.code(), -32021);
388        assert_eq!(ErrorCode::OnionHopsOutOfRange.code(), -32022);
389        assert_eq!(ErrorCode::Unauthorized.code(), -32030);
390        assert_eq!(ErrorCode::NotSupported.code(), -32031);
391        assert_eq!(ErrorCode::ControlError.code(), -32032);
392    }
393
394    /// **Proves:** the onion codes keep `-32020..-32022` and the control codes
395    /// are renumbered clear of them.
396    /// **Catches:** a regression that reintroduces the historical collision.
397    #[test]
398    fn onion_control_collision_resolved() {
399        assert_eq!(ErrorCode::OnionCircuitUnavailable.code(), -32020);
400        assert_eq!(ErrorCode::Unauthorized.code(), -32030);
401        assert_ne!(
402            ErrorCode::OnionCircuitUnavailable.code(),
403            ErrorCode::Unauthorized.code()
404        );
405    }
406
407    /// **Proves:** a code serializes as a bare integer, never a tagged object.
408    /// **Catches:** a swap of `Serialize_repr` for plain `Serialize`.
409    #[test]
410    fn code_serialises_as_integer() {
411        assert_eq!(
412            serde_json::to_string(&ErrorCode::MethodNotFound).unwrap(),
413            "-32601"
414        );
415        assert_eq!(
416            serde_json::to_string(&ErrorCode::ContentRedirect).unwrap(),
417            "-32008"
418        );
419    }
420
421    /// **Proves:** `ALL` lists exactly the distinct codes, with unique numbers
422    /// and unique machine strings.
423    /// **Catches:** a new variant left out of `ALL`, or a duplicated
424    /// code/machine string.
425    #[test]
426    fn all_codes_unique_and_complete() {
427        use std::collections::HashSet;
428        let nums: HashSet<i32> = ErrorCode::ALL.iter().map(|c| c.code()).collect();
429        let strs: HashSet<&str> = ErrorCode::ALL.iter().map(|c| c.machine_code()).collect();
430        assert_eq!(nums.len(), ErrorCode::ALL.len(), "duplicate numeric code");
431        assert_eq!(strs.len(), ErrorCode::ALL.len(), "duplicate machine code");
432        assert_eq!(ErrorCode::ALL.len(), 23);
433    }
434
435    /// **Proves:** the constructor mints the full `{code, message, data:{code,
436    /// origin}}` envelope and `data.code` mirrors the numeric code.
437    /// **Catches:** a drift between the numeric code and `data.code`.
438    #[test]
439    fn envelope_shape_and_data_code() {
440        let e = RpcError::new(
441            ErrorCode::ResourceUnavailable,
442            "not here",
443            ErrorOrigin::Node,
444        );
445        let v = serde_json::to_value(&e).unwrap();
446        assert_eq!(v["code"], -32004);
447        assert_eq!(v["message"], "not here");
448        assert_eq!(v["data"]["code"], "RESOURCE_UNAVAILABLE");
449        assert_eq!(v["data"]["origin"], "node");
450        // Round-trips.
451        let back: RpcError = serde_json::from_value(v).unwrap();
452        assert_eq!(back, e);
453    }
454
455    /// **Proves:** `UpstreamError` defaults to the `upstream` origin.
456    #[test]
457    fn upstream_default_origin() {
458        let e = RpcError::of(ErrorCode::UpstreamError, "upstream: boom");
459        assert_eq!(e.data.origin, ErrorOrigin::Upstream);
460        assert_eq!(
461            serde_json::to_value(&e).unwrap()["data"]["origin"],
462            "upstream"
463        );
464    }
465
466    /// **Proves:** `code_only` uses the default message + origin.
467    #[test]
468    fn code_only_defaults() {
469        let e = RpcError::code_only(ErrorCode::PeerUnreachable);
470        assert_eq!(e.message, "Peer unreachable");
471        assert_eq!(e.data.origin, ErrorOrigin::Peer);
472    }
473}