-
Notifications
You must be signed in to change notification settings - Fork 420
fix: no Debug on Display implementations
#2083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2f1f380
f814bbb
c39ade4
961118b
d65eed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,10 +256,28 @@ pub enum CalculateFeeError { | |
| impl fmt::Display for CalculateFeeError { | ||
| fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| CalculateFeeError::MissingTxOut(outpoints) => write!( | ||
| f, | ||
| "missing `TxOut` for one or more of the inputs of the tx: {outpoints:?}", | ||
| ), | ||
| CalculateFeeError::MissingTxOut(outpoints) => { | ||
| let max_show = 3; | ||
| let shown = outpoints.iter().take(max_show); | ||
| let remaining = outpoints.len().saturating_sub(max_show); | ||
|
|
||
| write!(f, "missing `TxOut` for input(s)")?; | ||
| if outpoints.is_empty() { | ||
| write!(f, ": <none>") | ||
| } else { | ||
| write!(f, ": ")?; | ||
| for (i, op) in shown.enumerate() { | ||
| if i > 0 { | ||
| write!(f, ", ")?; | ||
| } | ||
| write!(f, "{}", op)?; | ||
| } | ||
| if remaining > 0 { | ||
| write!(f, " (+{} more)", remaining)?; | ||
| } | ||
|
Comment on lines
+259
to
+277
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs
index 457a478a..d170eccf 100644
--- a/crates/chain/src/tx_graph.rs
+++ b/crates/chain/src/tx_graph.rs
@@ -258,19 +258,16 @@ impl fmt::Display for CalculateFeeError {
match self {
CalculateFeeError::MissingTxOut(outpoints) => {
let max_show = 3;
- let shown = outpoints.iter().take(max_show);
+ let shown: Vec<_> = outpoints.iter().take(max_show).collect();
let remaining = outpoints.len().saturating_sub(max_show);
write!(f, "missing `TxOut` for input(s)")?;
if outpoints.is_empty() {
write!(f, ": <none>")
} else {
- write!(f, ": ")?;
- for (i, op) in shown.enumerate() {
- if i > 0 {
- write!(f, ", ")?;
- }
- write!(f, "{}", op)?;
+ write!(f, ": {}", shown[0])?;
+ for op in &shown[1..] {
+ write!(f, ", {}", op)?;
}
if remaining > 0 {
write!(f, " (+{} more)", remaining)?; |
||
| Ok(()) | ||
| } | ||
| } | ||
| CalculateFeeError::NegativeFee(fee) => write!( | ||
| f, | ||
| "transaction is invalid according to the graph and has negative fee: {}", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,18 @@ pub enum StoreError { | |
| impl core::fmt::Display for StoreError { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| match self { | ||
| Self::Io(e) => write!(f, "io error trying to read file: {e}"), | ||
| Self::InvalidMagicBytes { got, expected } => write!( | ||
| f, | ||
| "file has invalid magic bytes: expected={expected:?} got={got:?}", | ||
| ), | ||
| Self::Io(e) => write!(f, "io error trying to read file: {}", e), | ||
| Self::InvalidMagicBytes { got, expected } => { | ||
| write!(f, "file has invalid magic bytes: expected=0x")?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error: could not open file store
Caused by:
file has invalid magic bytes: expected=0x62646b5f6578616d706c655f656c65637472756d got=0x62646b5f6578616d706c5f656c65637472756d01Given the format of the error output I would use This is a good opportunity to rewrite the others in the same spirit. Also, stacking Error: could not open file store
Caused by:
invalid magic bytes
expected: 0x62646b5f6578616d706c655f656c65637472756d
got: 0x62646b5f6578616d706c5f656c65637472756d01 |
||
| for b in expected { | ||
| write!(f, "{:02x}", b)?; | ||
| } | ||
| write!(f, " got=0x")?; | ||
| for b in got { | ||
| write!(f, "{:02x}", b)?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| Self::Bincode(e) => write!(f, "bincode error while reading entry {e}"), | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,8 +215,20 @@ fn main() -> anyhow::Result<()> { | |
| .chain_tip(local_tip.clone()) | ||
| .inspect(|item, progress| { | ||
| let pc = (100 * progress.consumed()) as f32 / progress.total() as f32; | ||
| eprintln!("[ SCANNING {pc:03.0}% ] {item}"); | ||
| // Flush early to ensure we print at every iteration. | ||
| match item { | ||
| bdk_chain::spk_client::SyncItem::Spk((keychain, index), spk) => { | ||
| eprintln!( | ||
| "[ SCANNING {pc:03.0}% ] script {} {} {}", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I prefer to |
||
| keychain, index, spk | ||
| ); | ||
| } | ||
| bdk_chain::spk_client::SyncItem::Txid(txid) => { | ||
| eprintln!("[ SCANNING {pc:03.0}% ] txid {}", txid); | ||
| } | ||
| bdk_chain::spk_client::SyncItem::OutPoint(op) => { | ||
| eprintln!("[ SCANNING {pc:03.0}% ] outpoint {}", op); | ||
| } | ||
| } | ||
| let _ = io::stderr().flush(); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this with the following
bin:I think the output is not very clear:
I would keep only a fixed size prefix in the output, including the descriptor type and trying to capture the origin keypath if possible.
@qatkk proposed to increase the suffix to capture the checksum, but without any clear accessors to those components it is a "best guess" effort.
Maybe we should propose the implementation of them at the
miniscriptlevel, and add methods to get strings fromDescriptorTypefor example.