From: Dmenec Date: Thu, 11 Dec 2025 10:53:32 +0000 (+0100) Subject: fix(chain)!: remove Debug usage and implement Display for InsertDescriptorError X-Git-Url: http://internal-gitweb-vhost/%22https:/parse/scripts/-sqlite/database/struct.MemoryDatabase.html?a=commitdiff_plain;h=5d715c2e4c8076be058e342efe279a3fc3481312;p=bdk fix(chain)!: remove Debug usage and implement Display for InsertDescriptorError Replace Debug-based formatting with user-friendly Display messages. --- diff --git a/crates/chain/src/indexer/keychain_txout.rs b/crates/chain/src/indexer/keychain_txout.rs index 99931cf5..4500c091 100644 --- a/crates/chain/src/indexer/keychain_txout.rs +++ b/crates/chain/src/indexer/keychain_txout.rs @@ -973,25 +973,27 @@ pub enum InsertDescriptorError { }, } -impl core::fmt::Display for InsertDescriptorError { +impl core::fmt::Display for InsertDescriptorError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { InsertDescriptorError::DescriptorAlreadyAssigned { - existing_assignment: existing, + existing_assignment, descriptor, } => { write!( f, - "attempt to re-assign descriptor {descriptor:?} already assigned to {existing:?}" + "descriptor '{}' is already in use by another keychain '{}'", + descriptor, existing_assignment ) } InsertDescriptorError::KeychainAlreadyAssigned { - existing_assignment: existing, + existing_assignment, keychain, } => { write!( f, - "attempt to re-assign keychain {keychain:?} already assigned to {existing:?}" + "keychain '{}' is already associated with another descriptor '{}'", + keychain, existing_assignment ) } } @@ -999,7 +1001,7 @@ impl core::fmt::Display for InsertDescriptorError { } #[cfg(feature = "std")] -impl std::error::Error for InsertDescriptorError {} +impl std::error::Error for InsertDescriptorError {} /// `ChangeSet` represents persistent updates to a [`KeychainTxOutIndex`]. /// diff --git a/crates/chain/tests/test_keychain_txout_index.rs b/crates/chain/tests/test_keychain_txout_index.rs index 0cce8476..263a0fa8 100644 --- a/crates/chain/tests/test_keychain_txout_index.rs +++ b/crates/chain/tests/test_keychain_txout_index.rs @@ -18,6 +18,15 @@ enum TestKeychain { Internal, } +impl core::fmt::Display for TestKeychain { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + TestKeychain::External => write!(f, "External"), + TestKeychain::Internal => write!(f, "Internal"), + } + } +} + fn parse_descriptor(descriptor: &str) -> Descriptor { let secp = bdk_chain::bitcoin::secp256k1::Secp256k1::signing_only(); Descriptor::::parse_descriptor(&secp, descriptor)