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
60
61
62
63
64
65
66
67
68
69
use facet::Facet;
use std::fmt;
// r[rpc.fallible.vox-error]
/// Protocol-level error wrapper distinguishing application errors from vox infrastructure errors.
///
/// On the caller side, all return types are wrapped as `Result<T, VoxError<E>>`:
/// * Infallible `fn foo() -> T` becomes `Result<T, VoxError>`
/// * Fallible `fn foo() -> Result<T, E>` becomes `Result<T, VoxError<E>>`
#[derive(Debug, Clone, Facet)]
#[repr(u8)]
pub enum VoxError<E = ::core::convert::Infallible> {
/// The handler ran and returned an application error.
User(E),
/// No handler recognized the method ID.
UnknownMethod,
/// The arguments could not be deserialized.
InvalidPayload(String),
/// The call was cancelled before completion (e.g. handler dropped without replying).
Cancelled,
/// The underlying connection closed while the call was in flight.
ConnectionClosed,
/// The session shut down while the call was in flight.
SessionShutdown,
/// The call could not be sent because the transport is dead.
SendFailed,
/// The runtime refused to guess after recovery.
Indeterminate,
}
impl<E> VoxError<E> {
// r[impl rpc.fallible.vox-error.retryable]
// r[impl schema.errors.non-retryable]
/// Returns `true` if retrying the same operation on a fresh connection may succeed.
///
/// `InvalidPayload`, `UnknownMethod`, `User`, `Cancelled`, and `Indeterminate`
/// are permanent failures — retrying them against the same peer will reproduce
/// the same outcome.
pub fn is_retryable(&self) -> bool {
matches!(
self,
Self::ConnectionClosed | Self::SessionShutdown | Self::SendFailed
)
}
}
impl<E: fmt::Display> fmt::Display for VoxError<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::User(error) => write!(f, "{error}"),
Self::UnknownMethod => f.write_str("unknown vox method call"),
Self::InvalidPayload(message) => write!(f, "invalid vox payload: {message}"),
Self::Cancelled => f.write_str("vox request cancelled"),
Self::ConnectionClosed => f.write_str("vox connection closed"),
Self::SessionShutdown => f.write_str("vox session shutdown"),
Self::SendFailed => f.write_str("vox send failed"),
Self::Indeterminate => f.write_str("indeterminate vox error"),
}
}
}
impl<E: fmt::Debug + fmt::Display> std::error::Error for VoxError<E> {}