ndn_app/error.rs
1//! The error type shared by every fallible operation in this crate.
2//!
3//! Keeping all of them in one enum, rather than per-module error types,
4//! means callers of [`crate::app::AppHandler::express_interest`] and
5//! [`crate::app::App::start`] can match on the same [`enum@Error`]
6//! regardless of which layer produced it.
7
8use thiserror::Error;
9
10/// Failure modes that can occur while running an [`crate::app::App`] or
11/// expressing an Interest through an [`crate::app::AppHandler`].
12#[derive(Debug, Error)]
13pub enum Error {
14 /// Connecting to the local NFD forwarder failed, e.g. the Unix
15 /// socket doesn't exist or NFD isn't running.
16 #[error("Connection failed")]
17 ConnectionFailed,
18 /// The connection to NFD was closed, either by NFD or because a
19 /// background task exited. The app cannot continue after this.
20 #[error("Connection closed")]
21 ConnectionClosed,
22 /// An expressed Interest didn't receive a Data or NACK before its
23 /// `InterestLifetime` elapsed.
24 #[error("Operation timed out")]
25 Timeout,
26 /// The producer (or forwarder) NACKed the Interest, e.g. because it
27 /// failed the producer's verifier or no route matched.
28 #[error("Received a NACK for Interest")]
29 NackReceived,
30 /// A Data packet was received but rejected by the caller-supplied
31 /// [`crate::verifier::DataVerifier`].
32 #[error("Verification failed")]
33 VerificationFailed,
34 /// Reading from or writing to the NFD connection failed at the OS
35 /// level.
36 #[error("IO Error")]
37 IOError(std::io::Error),
38 /// A catch-all for errors that don't fit the other variants.
39 #[error("Other error")]
40 Other(String),
41}
42
43impl From<std::io::Error> for Error {
44 fn from(value: std::io::Error) -> Self {
45 Self::IOError(value)
46 }
47}
48
49impl From<tokio::time::error::Elapsed> for Error {
50 fn from(_: tokio::time::error::Elapsed) -> Self {
51 Self::Timeout
52 }
53}