-
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?
Conversation
492114b to
b73016e
Compare
|
Concept ACK — this approach looks good, thanks for the changes. I ran the tests locally and they all passed. While trying to recreate the initial issue’s scenario (#1933), I found that I have a few small suggestions below. Most of these are nits, but since this PR is already addressing the area, I thought it’d be reasonable to mention them here:
|
evanlinjin
left a comment
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.
Quality work.
Just a couple requested changes:
- Commit messages should contain a scope (as mentioned in the conventional commits spec). The scope should be the name of the package affected:
core,chain,example, etc. - Commits that break the API should be marked with
!.
And a nit:
- Error messages should be somewhat consistent. I personally don't think we should suggest actions in the message, just state what the error is.
|
@Dmenec are you able to make progress on this? |
b73016e to
532e2ec
Compare
|
@evanlinjin Pushed the updates. Let me know if everything checks out :) |
evanlinjin
left a comment
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.
utACK 532e2ec
I'm happy with how this is looking. Unable to test until I have access to a computer again.
8dd8a42 to
789d8a3
Compare
…iptorError Replace Debug-based formatting with user-friendly Display messages. Add helper to shorten descriptors for concise error output.
…eError Limited to 3 max shown items and added a suffix when there are additional entries.
…rror. Format magic bytes as 0x-prefixed hex.
789d8a3 to
d65eed0
Compare
|
Having some trouble with the no_std CI check for the esplora crate... Does it actually support no_std, or should be treated as std‑only? |
@Dmenec It's now fixed on master, a rebase should fix it. |
f0698e1 to
d65eed0
Compare
| 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)?; | ||
| } |
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.
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)?;| ), | ||
| 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")?; |
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.
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 invalid magic bytes without the file has.
This is a good opportunity to rewrite the others in the same spirit.
Also, stacking expected and got improves the feedback to the reader:
Error: could not open file store
Caused by:
invalid magic bytes
expected: 0x62646b5f6578616d706c655f656c65637472756d
got: 0x62646b5f6578616d706c5f656c65637472756d01| match item { | ||
| bdk_chain::spk_client::SyncItem::Spk((keychain, index), spk) => { | ||
| eprintln!( | ||
| "[ SCANNING {pc:03.0}% ] script {} {} {}", |
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.
nit: "[ SCANNING {pc:3.0}% ] script {} {} {}", instead of "[ SCANNING {pc:03.0}% ] script {} {} {}",
I prefer
[ SCANNING 6% ] outpoint 623cf110e23b15074e807a551a751856eb0a95f23a4a60f125d943d1d6e7cb6a:0
to
[ SCANNING 006% ] outpoint 623cf110e23b15074e807a551a751856eb0a95f23a4a60f125d943d1d6e7cb6a:0
| impl<K: core::fmt::Debug> core::fmt::Display for InsertDescriptorError<K> { | ||
| /// Returns a shortened string representation of a descriptor. | ||
| /// Shows the first and last `edge_len` characters, separated by `...`. | ||
| fn short_descriptor(desc: &Descriptor<DescriptorPublicKey>, edge_len: usize) -> String { |
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:
use bdk_chain::bitcoin::key::Secp256k1;
use bdk_chain::indexer::keychain_txout::KeychainTxOutIndex;
use bdk_chain::miniscript::Descriptor;
const DESC: &str = "...";
fn main() {
let lookahead = 10;
let use_cache = true;
let mut index = KeychainTxOutIndex::new(lookahead, use_cache);
let secp = Secp256k1::new();
let (desc, _) = Descriptor::parse_descriptor(&secp, DESC).unwrap();
index.insert_descriptor("some", desc.clone()).unwrap();
if let Err(e) = index.insert_descriptor("other", desc) {
eprintln!("{}", e);
}
}I think the output is not very clear:
descriptor 'tr([...d45f9rlk' is already in use by another keychain 'some'.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 miniscript level, and add methods to get strings from DescriptorType for example.
Description
Fixes #1933, remove the usage of
DebugonDisplayimplemetations mentioned in #1881 (comment)Changelog notice
Debugusage withDisplaymessages forInsertDescriptorError,CalculateFeeErrorandStoreError.InvalidMagicBytesnow displays expected and actual bytes in hexadecimal instead of usingDebug.short_descriptorfunction to shorten descriptors for concise error output.SyncRequestDisplayfor Esplora and Electrum examples.Checklists
All Submissions:
just check,just fmtandjust testbefore committing