/ bin / drk / src / error.rs
error.rs
 1  /* This file is part of DarkFi (https://dark.fi)
 2   *
 3   * Copyright (C) 2020-2025 Dyne.org foundation
 4   *
 5   * This program is free software: you can redistribute it and/or modify
 6   * it under the terms of the GNU Affero General Public License as
 7   * published by the Free Software Foundation, either version 3 of the
 8   * License, or (at your option) any later version.
 9   *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Affero General Public License for more details.
14   *
15   * You should have received a copy of the GNU Affero General Public License
16   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17   */
18  
19  /// Result type used in the wallet database module
20  pub type WalletDbResult<T> = std::result::Result<T, WalletDbError>;
21  
22  /// Custom wallet database errors available for drk.
23  /// Please sort them sensefully.
24  #[derive(Debug)]
25  pub enum WalletDbError {
26      // Initialization error
27      InitializationFailed = -32100,
28  
29      // Connection related errors
30      ConnectionFailed = -32110,
31      FailedToAquireLock = -32111,
32  
33      // Configuration related errors
34      PragmaUpdateError = -32120,
35  
36      // Query execution related errors
37      QueryPreparationFailed = -32130,
38      QueryExecutionFailed = -32131,
39      QueryFinalizationFailed = -32132,
40      ParseColumnValueError = -32133,
41      RowNotFound = -32134,
42  
43      // Generic error
44      GenericError = -32140,
45  }
46  
47  impl std::fmt::Display for WalletDbError {
48      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49          match self {
50              WalletDbError::InitializationFailed => write!(f, "WalletDbError::InitializationFailed"),
51              WalletDbError::ConnectionFailed => write!(f, "WalletDbError::ConnectionFailed"),
52              WalletDbError::FailedToAquireLock => write!(f, "WalletDbError::FailedToAquireLock"),
53              WalletDbError::PragmaUpdateError => write!(f, "WalletDbError::PragmaUpdateError"),
54              WalletDbError::QueryPreparationFailed => {
55                  write!(f, "WalletDbError::QueryPreparationFailed")
56              }
57              WalletDbError::QueryExecutionFailed => write!(f, "WalletDbError::QueryExecutionFailed"),
58              WalletDbError::QueryFinalizationFailed => {
59                  write!(f, "WalletDbError::QueryFinalizationFailed")
60              }
61              WalletDbError::ParseColumnValueError => {
62                  write!(f, "WalletDbError::ParseColumnValueError")
63              }
64              WalletDbError::RowNotFound => write!(f, "WalletDbError::RowNotFound"),
65              WalletDbError::GenericError => write!(f, "WalletDbError::GenericError"),
66          }
67      }
68  }
69  
70  impl std::error::Error for WalletDbError {}