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
// Copyright (c) 2022-2023 Yuki Kishimoto
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

use deadpool_sqlite::{CreatePoolError, InteractError, PoolError};
use nostr_database::{flatbuffers, DatabaseError};
use thiserror::Error;

use crate::migration::MigrationError;

/// Store error
#[derive(Debug, Error)]
pub enum Error {
    /// Sqlite error
    #[error(transparent)]
    Sqlite(#[from] rusqlite::Error),
    /// Pool error
    #[error(transparent)]
    CreateDeadPool(#[from] CreatePoolError),
    /// Pool error
    #[error(transparent)]
    DeadPool(#[from] PoolError),
    /// Pool error
    #[error("{0}")]
    DeadPoolInteract(String),
    /// Migration error
    #[error(transparent)]
    Migration(#[from] MigrationError),
    /// Database error
    #[error(transparent)]
    Database(#[from] DatabaseError),
    /// Flatbuffers error
    #[error(transparent)]
    Flatbuffers(#[from] flatbuffers::Error),
    /// Url error
    #[error(transparent)]
    Url(#[from] nostr::url::ParseError),
    /// Not found
    #[error("sqlite: {0} not found")]
    NotFound(String),
}

impl From<InteractError> for Error {
    fn from(e: InteractError) -> Self {
        Self::DeadPoolInteract(e.to_string())
    }
}

impl From<Error> for DatabaseError {
    fn from(e: Error) -> Self {
        Self::backend(e)
    }
}