Skip to content

Commit 5d715c2

Browse files
committed
fix(chain)!: remove Debug usage and implement Display for InsertDescriptorError
Replace Debug-based formatting with user-friendly Display messages.
1 parent be356d5 commit 5d715c2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

crates/chain/src/indexer/keychain_txout.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -973,33 +973,35 @@ pub enum InsertDescriptorError<K> {
973973
},
974974
}
975975

976-
impl<K: core::fmt::Debug> core::fmt::Display for InsertDescriptorError<K> {
976+
impl<K: core::fmt::Display> core::fmt::Display for InsertDescriptorError<K> {
977977
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
978978
match self {
979979
InsertDescriptorError::DescriptorAlreadyAssigned {
980-
existing_assignment: existing,
980+
existing_assignment,
981981
descriptor,
982982
} => {
983983
write!(
984984
f,
985-
"attempt to re-assign descriptor {descriptor:?} already assigned to {existing:?}"
985+
"descriptor '{}' is already in use by another keychain '{}'",
986+
descriptor, existing_assignment
986987
)
987988
}
988989
InsertDescriptorError::KeychainAlreadyAssigned {
989-
existing_assignment: existing,
990+
existing_assignment,
990991
keychain,
991992
} => {
992993
write!(
993994
f,
994-
"attempt to re-assign keychain {keychain:?} already assigned to {existing:?}"
995+
"keychain '{}' is already associated with another descriptor '{}'",
996+
keychain, existing_assignment
995997
)
996998
}
997999
}
9981000
}
9991001
}
10001002

10011003
#[cfg(feature = "std")]
1002-
impl<K: core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
1004+
impl<K: core::fmt::Display + core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
10031005

10041006
/// `ChangeSet` represents persistent updates to a [`KeychainTxOutIndex`].
10051007
///

crates/chain/tests/test_keychain_txout_index.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ enum TestKeychain {
1818
Internal,
1919
}
2020

21+
impl core::fmt::Display for TestKeychain {
22+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23+
match self {
24+
TestKeychain::External => write!(f, "External"),
25+
TestKeychain::Internal => write!(f, "Internal"),
26+
}
27+
}
28+
}
29+
2130
fn parse_descriptor(descriptor: &str) -> Descriptor<DescriptorPublicKey> {
2231
let secp = bdk_chain::bitcoin::secp256k1::Secp256k1::signing_only();
2332
Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, descriptor)

0 commit comments

Comments
 (0)