tor_dirserver/err.rs
1//! Error module for `tor-dirserver`.
2
3use thiserror::Error;
4
5/// An error while interacting with a database.
6///
7/// This error should be returned by all functions that interact with the
8/// database in one way or another.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub(crate) enum DatabaseError {
12 /// A low-level SQLite error has occurred, which can have a bascially
13 /// infinite amount of reasons, all of them outlined in the actual SQLite
14 /// and [`rusqlite`] documentation.
15 #[error("low-level rusqlite error: {0}")]
16 LowLevel(#[from] rusqlite::Error),
17
18 /// This is an application level error meaning that the database can be
19 /// successfully accessed but its content implies it is of a schema version
20 /// we do not support.
21 ///
22 /// Keep in mind that an unrecognized schema is not equal to no schema.
23 /// In the latter case we actually initialize the database, whereas in the
24 /// previous one, we fail early in order to not corrupt an existing database.
25 /// Future versions of this crate should continue with this promise in order
26 /// to ensure forward compatability.
27 #[error("incompatible schema version: {version}")]
28 IncompatibleSchema {
29 /// The incompatible schema version found in the database.
30 version: String,
31 },
32
33 /// Interaction with our database pool, [`r2d2`], has failed.
34 ///
35 /// Unlike other database pools, this error is fairly straightforward and
36 /// may only be obtained in the cases in which we try to obtain a connection
37 /// handle from the pool. Notably, it does not fail if, for example,
38 /// the low-level [`rusqlite`] has a failure.
39 #[error("pool error: {0}")]
40 Pool(#[from] r2d2::Error),
41
42 /// An internal error.
43 #[error("Internal error")]
44 Bug(#[from] tor_error::Bug),
45}
46
47/// An unrecoverable error during daemon operation.
48///
49/// This error is inteded for functions that generally run forever, unless they
50/// encounter an error that is not recoverable, in which case, they will return
51/// this error type.
52#[derive(Debug, Error)]
53#[non_exhaustive]
54pub(crate) enum FatalError {
55 /// The selection of a consensus from the database has failed.
56 ///
57 /// This most likely indicates that something with the underlying database
58 /// is wrong in a persistent fashion, i.e. retries will not work anymore.
59 #[error("consensus selection error: {0}")]
60 ConsensusSelection(DatabaseError),
61}