Skip to content

Commit 118cc19

Browse files
committed
Use thiserror throughout testnet/stacks-node
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a335dcd commit 118cc19

File tree

7 files changed

+22
-42
lines changed

7 files changed

+22
-42
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rand = "0.8"
2121
rand_chacha = "0.3.1"
2222
tikv-jemallocator = "0.5.4"
2323
rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] }
24+
thiserror = { version = "1.0.65" }
2425

2526
# Use a bit more than default optimization for
2627
# dev builds to speed up test execution

libsigner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ slog-term = "2.6.0"
3030
slog-json = { version = "2.3.0", optional = true }
3131
stacks-common = { path = "../stacks-common" }
3232
stackslib = { path = "../stackslib"}
33-
thiserror = "1.0"
33+
thiserror = { workspace = true }
3434
tiny_http = "0.12"
3535

3636
[dev-dependencies]

stacks-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ slog-json = { version = "2.3.0", optional = true }
3838
slog-term = "2.6.0"
3939
stacks-common = { path = "../stacks-common" }
4040
stackslib = { path = "../stackslib" }
41-
thiserror = "1.0"
41+
thiserror = { workspace = true }
4242
tiny_http = { version = "0.12", optional = true }
4343
toml = "0.5.6"
4444
tracing = "0.1.37"

testnet/stacks-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ rusqlite = { workspace = true }
3232
async-h1 = { version = "2.3.2", optional = true }
3333
async-std = { version = "1.6", optional = true, features = ["attributes"] }
3434
http-types = { version = "2.12", optional = true }
35+
thiserror = { workspace = true }
3536

3637
[target.'cfg(not(any(target_os = "macos", target_os="windows", target_arch = "arm")))'.dependencies]
3738
tikv-jemallocator = {workspace = true}

testnet/stacks-node/src/burnchains/mod.rs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub mod bitcoin_regtest_controller;
22
pub mod mocknet_controller;
33

4-
use std::fmt;
54
use std::time::Instant;
65

76
use stacks::burnchains;
@@ -16,41 +15,26 @@ pub use self::bitcoin_regtest_controller::{make_bitcoin_indexer, BitcoinRegtestC
1615
pub use self::mocknet_controller::MocknetController;
1716
use super::operations::BurnchainOpSigner;
1817

19-
#[derive(Debug)]
18+
#[derive(Debug, thiserror::Error)]
2019
pub enum Error {
20+
#[error("ChainsCoordinator closed")]
2121
CoordinatorClosed,
22-
IndexerError(burnchains::Error),
22+
#[error("Indexer error: {0}")]
23+
IndexerError(#[from] burnchains::Error),
24+
#[error("Burnchain error")]
2325
BurnchainError,
26+
#[error("Max fee rate exceeded")]
2427
MaxFeeRateExceeded,
28+
#[error("Identical operation, not submitting")]
2529
IdenticalOperation,
30+
#[error("No UTXOs available")]
2631
NoUTXOs,
32+
#[error("Transaction submission failed: {0}")]
2733
TransactionSubmissionFailed(String),
34+
#[error("Serializer error: {0}")]
2835
SerializerError(CodecError),
2936
}
3037

31-
impl fmt::Display for Error {
32-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33-
match self {
34-
Error::CoordinatorClosed => write!(f, "ChainsCoordinator closed"),
35-
Error::IndexerError(ref e) => write!(f, "Indexer error: {:?}", e),
36-
Error::BurnchainError => write!(f, "Burnchain error"),
37-
Error::MaxFeeRateExceeded => write!(f, "Max fee rate exceeded"),
38-
Error::IdenticalOperation => write!(f, "Identical operation, not submitting"),
39-
Error::NoUTXOs => write!(f, "No UTXOs available"),
40-
Error::TransactionSubmissionFailed(e) => {
41-
write!(f, "Transaction submission failed: {e}")
42-
}
43-
Error::SerializerError(e) => write!(f, "Serializer error: {e}"),
44-
}
45-
}
46-
}
47-
48-
impl From<burnchains::Error> for Error {
49-
fn from(e: burnchains::Error) -> Self {
50-
Error::IndexerError(e)
51-
}
52-
}
53-
5438
pub trait BurnchainController {
5539
fn start(&mut self, target_block_height_opt: Option<u64>)
5640
-> Result<(BurnchainTip, u64), Error>;

testnet/stacks-node/src/tests/bitcoin_regtest.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ use crate::helium::RunLoop;
1717
use crate::tests::to_addr;
1818
use crate::Config;
1919

20-
#[derive(Debug)]
20+
#[derive(Debug, thiserror::Error)]
2121
pub enum BitcoinCoreError {
22+
#[error("bitcoind spawn failed: {0}")]
2223
SpawnFailed(String),
24+
#[error("bitcoind stop failed: {0}")]
2325
StopFailed(String),
2426
}
2527

26-
impl std::fmt::Display for BitcoinCoreError {
27-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28-
match self {
29-
Self::SpawnFailed(msg) => write!(f, "bitcoind spawn failed: {msg}"),
30-
Self::StopFailed(msg) => write!(f, "bitcoind stop failed: {msg}"),
31-
}
32-
}
33-
}
34-
3528
type BitcoinResult<T> = Result<T, BitcoinCoreError>;
3629

3730
pub struct BitcoinCoreController {

0 commit comments

Comments
 (0)