diff --git a/Cargo.lock b/Cargo.lock index 227cd9d768..8a3769b6a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3328,6 +3328,7 @@ dependencies = [ "stackslib", "stx-genesis", "tempfile", + "thiserror", "tikv-jemallocator", "tiny_http", "tokio", @@ -3592,18 +3593,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 10dc427e2e..c00c223c47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ rand = "0.8" rand_chacha = "0.3.1" tikv-jemallocator = "0.5.4" rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] } +thiserror = { version = "1.0.65" } # Use a bit more than default optimization for # dev builds to speed up test execution diff --git a/libsigner/Cargo.toml b/libsigner/Cargo.toml index 63241d3256..7c472365a1 100644 --- a/libsigner/Cargo.toml +++ b/libsigner/Cargo.toml @@ -30,7 +30,7 @@ slog-term = "2.6.0" slog-json = { version = "2.3.0", optional = true } stacks-common = { path = "../stacks-common" } stackslib = { path = "../stackslib"} -thiserror = "1.0" +thiserror = { workspace = true } tiny_http = "0.12" [dev-dependencies] diff --git a/stacks-signer/Cargo.toml b/stacks-signer/Cargo.toml index da94cc10de..139c34fba8 100644 --- a/stacks-signer/Cargo.toml +++ b/stacks-signer/Cargo.toml @@ -38,7 +38,7 @@ slog-json = { version = "2.3.0", optional = true } slog-term = "2.6.0" stacks-common = { path = "../stacks-common" } stackslib = { path = "../stackslib" } -thiserror = "1.0" +thiserror = { workspace = true } tiny_http = { version = "0.12", optional = true } toml = "0.5.6" tracing = "0.1.37" diff --git a/testnet/stacks-node/Cargo.toml b/testnet/stacks-node/Cargo.toml index 958820b491..0c68d22ee7 100644 --- a/testnet/stacks-node/Cargo.toml +++ b/testnet/stacks-node/Cargo.toml @@ -32,6 +32,7 @@ rusqlite = { workspace = true } async-h1 = { version = "2.3.2", optional = true } async-std = { version = "1.6", optional = true, features = ["attributes"] } http-types = { version = "2.12", optional = true } +thiserror = { workspace = true } [target.'cfg(not(any(target_os = "macos", target_os="windows", target_arch = "arm")))'.dependencies] tikv-jemallocator = {workspace = true} diff --git a/testnet/stacks-node/src/burnchains/mod.rs b/testnet/stacks-node/src/burnchains/mod.rs index 0c9446304d..0509993dd0 100644 --- a/testnet/stacks-node/src/burnchains/mod.rs +++ b/testnet/stacks-node/src/burnchains/mod.rs @@ -1,7 +1,6 @@ pub mod bitcoin_regtest_controller; pub mod mocknet_controller; -use std::fmt; use std::time::Instant; use stacks::burnchains; @@ -16,41 +15,26 @@ pub use self::bitcoin_regtest_controller::{make_bitcoin_indexer, BitcoinRegtestC pub use self::mocknet_controller::MocknetController; use super::operations::BurnchainOpSigner; -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum Error { + #[error("ChainsCoordinator closed")] CoordinatorClosed, - IndexerError(burnchains::Error), + #[error("Indexer error: {0}")] + IndexerError(#[from] burnchains::Error), + #[error("Burnchain error")] BurnchainError, + #[error("Max fee rate exceeded")] MaxFeeRateExceeded, + #[error("Identical operation, not submitting")] IdenticalOperation, + #[error("No UTXOs available")] NoUTXOs, + #[error("Transaction submission failed: {0}")] TransactionSubmissionFailed(String), + #[error("Serializer error: {0}")] SerializerError(CodecError), } -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Error::CoordinatorClosed => write!(f, "ChainsCoordinator closed"), - Error::IndexerError(ref e) => write!(f, "Indexer error: {:?}", e), - Error::BurnchainError => write!(f, "Burnchain error"), - Error::MaxFeeRateExceeded => write!(f, "Max fee rate exceeded"), - Error::IdenticalOperation => write!(f, "Identical operation, not submitting"), - Error::NoUTXOs => write!(f, "No UTXOs available"), - Error::TransactionSubmissionFailed(e) => { - write!(f, "Transaction submission failed: {e}") - } - Error::SerializerError(e) => write!(f, "Serializer error: {e}"), - } - } -} - -impl From for Error { - fn from(e: burnchains::Error) -> Self { - Error::IndexerError(e) - } -} - pub trait BurnchainController { fn start(&mut self, target_block_height_opt: Option) -> Result<(BurnchainTip, u64), Error>; diff --git a/testnet/stacks-node/src/tests/bitcoin_regtest.rs b/testnet/stacks-node/src/tests/bitcoin_regtest.rs index 621f92aa47..90b1310183 100644 --- a/testnet/stacks-node/src/tests/bitcoin_regtest.rs +++ b/testnet/stacks-node/src/tests/bitcoin_regtest.rs @@ -17,21 +17,14 @@ use crate::helium::RunLoop; use crate::tests::to_addr; use crate::Config; -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum BitcoinCoreError { + #[error("bitcoind spawn failed: {0}")] SpawnFailed(String), + #[error("bitcoind stop failed: {0}")] StopFailed(String), } -impl std::fmt::Display for BitcoinCoreError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::SpawnFailed(msg) => write!(f, "bitcoind spawn failed: {msg}"), - Self::StopFailed(msg) => write!(f, "bitcoind stop failed: {msg}"), - } - } -} - type BitcoinResult = Result; pub struct BitcoinCoreController {