| Crates.io | brk_error |
| lib.rs | brk_error |
| version | 0.0.109 |
| created_at | 2025-08-07 19:24:23.075518+00 |
| updated_at | 2025-09-20 17:20:51.78456+00 |
| description | Errors used throughout BRK |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1785673 |
| size | 51,709 |
Centralized error handling for Bitcoin-related operations and database interactions.
This crate provides a unified error type that consolidates error handling across Bitcoin blockchain analysis tools. It wraps errors from multiple external libraries including Bitcoin Core RPC, database operations, HTTP requests, and serialization operations into a single Error enum.
Key Features:
Target Use Cases:
cargo add brk_error
use brk_error::{Error, Result};
fn process_transaction() -> Result<()> {
// Function automatically converts various error types
let data = std::fs::read("transaction.json")?; // IO error auto-converted
let parsed: serde_json::Value = serde_json::from_slice(&data)?; // JSON error auto-converted
// Custom domain errors
if data.len() < 32 {
return Err(Error::WrongLength);
}
Ok(())
}
Error: Main error enum consolidating all error typesResult<T, E = Error>: Type alias for std::result::Result with default Error typeExternal Library Errors:
BitcoinRPC: Bitcoin Core RPC client errorsBitcoinConsensusEncode: Bitcoin consensus encoding failuresFjall/VecDB/SeqDB: Database operation errorsMinreq: HTTP request errorsSerdeJson: JSON serialization errorsJiff: Date/time handling errorsZeroCopyError: Zero-copy conversion failuresDomain-Specific Errors:
WrongLength: Invalid data length for Bitcoin operationsWrongAddressType: Unsupported Bitcoin address formatUnindexableDate: Date outside valid blockchain range (before 2009-01-03)QuickCacheError: Cache operation failuresGeneric Errors:
Str(&'static str): Static string errorsString(String): Dynamic string errorsAll external error types automatically convert to Error via From trait implementations. The error type implements std::error::Error, Debug, and Display traits for comprehensive error reporting.
use brk_error::Result;
use bitcoincore_rpc::{Client, Auth};
fn get_block_count(client: &Client) -> Result<u64> {
let count = client.get_block_count()?; // Auto-converts bitcoincore_rpc::Error
Ok(count)
}
use brk_error::Result;
fn store_transaction_data(db: &fjall::Keyspace, data: &[u8]) -> Result<()> {
if data.len() != 32 {
return Err(brk_error::Error::WrongLength);
}
db.insert(b"tx_hash", data)?; // Auto-converts fjall::Error
Ok(())
}
use brk_error::{Error, Result};
use jiff::civil::Date;
fn validate_blockchain_date(date: Date) -> Result<()> {
let genesis_date = Date::constant(2009, 1, 3);
let earliest_valid = Date::constant(2009, 1, 9);
if date < genesis_date || (date > genesis_date && date < earliest_valid) {
return Err(Error::UnindexableDate);
}
Ok(())
}
Main Type: Error enum with 24 variants covering external libraries and domain-specific cases
Conversion Traits: Implements From for 10+ external error types enabling automatic error propagation
Error Handling: Standard Rust error handling with std::error::Error trait implementation
Dependencies: Integrates errors from bitcoin, bitcoincore-rpc, fjall, vecdb, jiff, minreq, serde_json, and zerocopy crates
Architecture: Centralized error aggregation pattern with automatic conversions and custom domain errors
This README was generated by Claude Code