ridl_rt/error.rs
1//! The error strata of ridl §10 that a runtime reports.
2//!
3//! Stratum 1, the errors an interface declares, is data and travels in a
4//! payload (§10.1). This module holds stratum 2, the contract errors (§10.2),
5//! and stratum 3, the detected infrastructure failures (§10.3).
6
7use crate::payload::Violation;
8
9/// A contract error, ridl §10.2. Derived from the contract and never declared.
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum Contract {
12 /// `INVALID_VALUE`: a payload breaks its typl constraints.
13 InvalidValue(Violation),
14 /// `PRECONDITION_FAILED`: a `require` clause evaluates to false.
15 PreconditionFailed,
16 /// `CONTRACT_BROKEN`: an `ensure` clause evaluates to false.
17 ContractBroken,
18 /// `UNKNOWN_INTERACTION`: the peers disagree on an interface number or an
19 /// ordinal.
20 UnknownInteraction,
21}
22
23/// An infrastructure failure that the runtime detected, ridl §10.3.
24#[non_exhaustive]
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub enum Transport {
27 /// The response bound passed without a reply.
28 Timeout,
29 /// A command received no delivery acknowledgment within its bound.
30 Undelivered,
31 /// The connection to the peer is lost.
32 Down,
33 /// A payload is not a well-formed encoding.
34 Corrupt,
35}
36
37/// The outcome of a call that did not succeed.
38#[derive(Clone, Copy, Debug, PartialEq, Eq)]
39pub enum CallError {
40 /// A contract error.
41 Contract(Contract),
42 /// An infrastructure failure.
43 Transport(Transport),
44}
45
46#[cfg(test)]
47mod tests {
48 use super::{CallError, Contract, Transport};
49
50 fn owns_nothing<T: Copy + Eq + core::fmt::Debug + 'static>() {}
51
52 #[test]
53 fn every_error_is_copy_and_owns_nothing() {
54 owns_nothing::<Contract>();
55 owns_nothing::<Transport>();
56 owns_nothing::<CallError>();
57 }
58}