nostr_database/
error.rs

1// Copyright (c) 2022-2023 Yuki Kishimoto
2// Copyright (c) 2023-2025 Rust Nostr Developers
3// Distributed under the MIT software license
4
5//! Nostr Database Error
6
7use std::fmt;
8
9/// Database Error
10#[derive(Debug)]
11pub enum DatabaseError {
12    /// An error happened in the underlying database backend.
13    Backend(Box<dyn std::error::Error + Send + Sync>),
14    /// Not supported
15    NotSupported,
16}
17
18impl std::error::Error for DatabaseError {}
19
20impl fmt::Display for DatabaseError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::Backend(e) => e.fmt(f),
24            Self::NotSupported => f.write_str("not supported"),
25        }
26    }
27}
28
29impl DatabaseError {
30    /// Create a new backend error
31    ///
32    /// Shorthand for `Error::Backend(Box::new(error))`.
33    #[inline]
34    pub fn backend<E>(error: E) -> Self
35    where
36        E: std::error::Error + Send + Sync + 'static,
37    {
38        Self::Backend(Box::new(error))
39    }
40}