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
|
//! Error module for `tor-dirserver`.
use thiserror::Error;
/// An error while interacting with a database.
///
/// This error should be returned by all functions that interact with the
/// database in one way or another.
#[derive(Debug, Error)]
#[non_exhaustive]
pub(crate) enum DatabaseError {
/// A low-level SQLite error has occurred, which can have a bascially
/// infinite amount of reasons, all of them outlined in the actual SQLite
/// and [`rusqlite`] documentation.
#[error("low-level rusqlite error: {0}")]
LowLevel(#[from] rusqlite::Error),
/// This is an application level error meaning that the database can be
/// successfully accessed but its content implies it is of a schema version
/// we do not support.
///
/// Keep in mind that an unrecognized schema is not equal to no schema.
/// In the latter case we actually initialize the database, whereas in the
/// previous one, we fail early in order to not corrupt an existing database.
/// Future versions of this crate should continue with this promise in order
/// to ensure forward compatability.
#[error("incompatible schema version: {version}")]
IncompatibleSchema {
/// The incompatible schema version found in the database.
version: String,
},
/// Interaction with our database pool, [`r2d2`], has failed.
///
/// Unlike other database pools, this error is fairly straightforward and
/// may only be obtained in the cases in which we try to obtain a connection
/// handle from the pool. Notably, it does not fail if, for example,
/// the low-level [`rusqlite`] has a failure.
#[error("pool error: {0}")]
Pool(#[from] r2d2::Error),
/// An internal error.
#[error("Internal error")]
Bug(#[from] tor_error::Bug),
}
/// An unrecoverable error during daemon operation.
///
/// This error is inteded for functions that generally run forever, unless they
/// encounter an error that is not recoverable, in which case, they will return
/// this error type.
#[derive(Debug, Error)]
#[non_exhaustive]
pub(crate) enum FatalError {
/// The selection of a consensus from the database has failed.
///
/// This most likely indicates that something with the underlying database
/// is wrong in a persistent fashion, i.e. retries will not work anymore.
#[error("consensus selection error: {0}")]
ConsensusSelection(DatabaseError),
}
|