]> Untitled Git - bdk/commitdiff
fix(chain)!: remove Debug usage and implement Display for InsertDescriptorError
authorDmenec <Domenec.Madrid@uab.cat>
Thu, 11 Dec 2025 10:53:32 +0000 (11:53 +0100)
committerDmenec <Domenec.Madrid@uab.cat>
Thu, 5 Feb 2026 11:50:08 +0000 (12:50 +0100)
Replace Debug-based formatting with user-friendly Display messages.

crates/chain/src/indexer/keychain_txout.rs
crates/chain/tests/test_keychain_txout_index.rs

index 99931cf5ed5f7a5e3bed6e5783ab88da961200f4..4500c091350cc5e52b0d5cc0509d2ac4c5f3290c 100644 (file)
@@ -973,25 +973,27 @@ pub enum InsertDescriptorError<K> {
     },
 }
 
-impl<K: core::fmt::Debug> core::fmt::Display for InsertDescriptorError<K> {
+impl<K: core::fmt::Display> core::fmt::Display for InsertDescriptorError<K> {
     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<K: core::fmt::Debug> core::fmt::Display for InsertDescriptorError<K> {
 }
 
 #[cfg(feature = "std")]
-impl<K: core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
+impl<K: core::fmt::Display + core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
 
 /// `ChangeSet` represents persistent updates to a [`KeychainTxOutIndex`].
 ///
index 0cce8476dc55fa8e9d7ea6c11e0c95dc940b73f2..263a0fa86ff2997df03ddcf01f98fbae49bc3157 100644 (file)
@@ -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<DescriptorPublicKey> {
     let secp = bdk_chain::bitcoin::secp256k1::Secp256k1::signing_only();
     Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, descriptor)