tor_dirserver/err.rs
1//! Error module for `tor-dirserver`
2//!
3//! TODO DIRMIRROR: The way on how we structure errors needs further discussion.
4
5#[allow(unused_imports)]
6use deadpool::managed::Pool;
7#[allow(unused_imports)]
8use std::sync::PoisonError;
9
10use thiserror::Error;
11
12/// An error while building a builder struct to the target structure.
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum BuilderError {
16 /// Some builders have mandatory fields (i.e. fields that must be set before
17 /// calling `.build()`). In those cases, we need to yield a semantic error.
18 #[error("missing field: {0}")]
19 MissingField(&'static str),
20}
21
22/// An error while interacting with the database.
23#[derive(Debug, Error)]
24#[non_exhaustive]
25pub(crate) enum DatabaseError {
26 /// A low-level SQLite error, independent of deadpool, has occurred, which
27 /// can have a basically infinite amount of reasons, all of them outlined in
28 /// the actual SQLite and rusqlite documentations.
29 #[error("low-level rusqlite error: {0}")]
30 LowLevel(#[from] rusqlite::Error),
31 /// This is an application level error meaning that the database can be
32 /// successfully accessed but its content implies it is of a schema version
33 /// we do not support.
34 ///
35 /// Keep in mind that an unrecognized schema is not equal to no schema.
36 /// In the latter case we actually initialize the database, whereas in the
37 /// previous one, we fail early in order to not corrupt an existing database.
38 /// Future versions of this crate should continue with this promise in order
39 /// to ensure forward compatability.
40 #[error("unrecognized schema version: {0}")]
41 IncompatibleSchema(String),
42}
43
44/// An error related around the HTTP protocol.
45#[derive(Debug, Error)]
46#[non_exhaustive]
47pub(crate) enum HttpError {
48 /// The `Content-Encoding` and/or `Accept-Encoding` header are (partially)
49 /// invalid.
50 #[error("invalid encoding: {0}")]
51 InvalidEncoding(String),
52}
53
54/// An error related around the StoreCache.
55#[derive(Debug, Error)]
56#[non_exhaustive]
57pub(crate) enum StoreCacheError {
58 /// An interaction with the database failed.
59 #[error("database error: {0}")]
60 Database(#[from] DatabaseError),
61 /// An underlying programming problem.
62 #[error("internal problem")]
63 Bug(#[from] tor_error::Bug),
64}