Skip to content

Commit

Permalink
Merge pull request #54 from mempool/junderw/limit-error-fix
Browse files Browse the repository at this point in the history
Fix: Make error messages clearer
  • Loading branch information
softsimon authored Nov 12, 2023
2 parents 9d6e266 + ab7cb3d commit 649f28d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@ fn get_history(
) -> Result<Vec<(Txid, Option<BlockId>)>> {
// to avoid silently trunacting history entries, ask for one extra more than the limit and fail if it exists
let history_txids = query.history_txids(scripthash, txs_limit + 1);
ensure!(history_txids.len() <= txs_limit, ErrorKind::TooPopular);
ensure!(
history_txids.len() <= txs_limit,
ErrorKind::TooManyTxs(txs_limit)
);
Ok(history_txids)
}

Expand Down
11 changes: 8 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ error_chain! {
display("Iterrupted by signal {}", sig)
}

TooPopular {
description("Too many history entries")
display("Too many history entries")
TooManyUtxos(limit: usize) {
description("Too many unspent transaction outputs. Contact support to raise limits.")
display("Too many unspent transaction outputs (>{}). Contact support to raise limits.", limit)
}

TooManyTxs(limit: usize) {
description("Too many history transactions. Contact support to raise limits.")
display("Too many history transactions (>{}). Contact support to raise limits.", limit)
}

#[cfg(feature = "electrum-discovery")]
Expand Down
2 changes: 1 addition & 1 deletion src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl ChainQuery {

// abort if the utxo set size excedees the limit at any point in time
if utxos.len() > limit {
bail!(ErrorKind::TooPopular)
bail!(ErrorKind::TooManyUtxos(limit))
}
}

Expand Down

0 comments on commit 649f28d

Please sign in to comment.