Skip to content

Commit

Permalink
Merge pull request #7 from chainwayxyz/error_management
Browse files Browse the repository at this point in the history
Error interface overhaul
  • Loading branch information
ceyhunsen authored Jul 3, 2024
2 parents 60c1612 + 6bbb3fb commit bd8efc2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/ledger/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use thiserror::Error;
/// Ledger error types.
#[derive(Error, Debug)]
pub enum LedgerError {
#[error("Ledger returned a general error: {0}")]
General(String),
#[error("Transaction is not OK: {0}")]
#[error("Transaction error: {0}")]
Transaction(String),
#[error("UTXO cannot be spend: {0}")]
#[error("UTXO error: {0}")]
Utxo(String),
}

Expand Down
4 changes: 2 additions & 2 deletions src/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Ledger {
.iter()
.find(|tx| tx.compute_txid() == txid)
.ok_or(LedgerError::Transaction(format!(
"No transaction is matched with {}",
"No transaction with txid {} found in ledger",
txid
)))?
.to_owned();
Expand All @@ -81,7 +81,7 @@ impl Ledger {

if input_value < output_value {
return Err(LedgerError::Transaction(format!(
"Input value {} is not above or equal of output value {}",
"Input amount is smaller than output amount: {} < {}",
input_value, output_value
)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Ledger {
.output
.get(utxo.vout as usize)
.ok_or(LedgerError::Utxo(format!(
"vout {} couldn't be found in transaction with txid {}",
"Vout {} couldn't be found in transaction with txid {}",
utxo.vout, utxo.txid
)))?;

Expand Down

0 comments on commit bd8efc2

Please sign in to comment.