Display implementations should not expose `Debug` output
Currently, the Display implementation for LoadError displaysDebug output for LoadError::MissingDescriptor and LoadError::Mismatch:
impl fmt::Display for LoadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LoadError::Descriptor(e) => e.fmt(f),
LoadError::MissingNetwork => write!(f, "loaded data is missing network type"),
LoadError::MissingGenesis => write!(f, "loaded data is missing genesis hash"),
LoadError::MissingDescriptor(k) => {
write!(f, "loaded data is missing descriptor for keychain {k:?}")
}
LoadError::Mismatch(mismatch) => write!(f, "data mismatch: {mismatch:?}"),
}
}
}
I think this is generally not a good practice. Debug output is automatically generated, and is not as nice to read as a hand-written Display implementation's output.
I noticed this in a test we were loading a wallet with the incorrect network, and instead of getting a nice error message, we got data mismatch: Network { loaded: Network::Testnet, expected: Network::Bitcoin }. Our project never exposes Debug output to the user, and we'd like to avoid doing this if we use BDK, but still be able to expose BDK errors to the user via Display.
Hello, is this issue available to work on?
For anyone following there is a PR in progress bitcoindevkit/bdk#1881 that addresses the issue in bdk_wallet. Check this comment https://github.com/bitcoindevkit/bdk/pull/1881#issuecomment-2718412512 for an idea of what remains to be fixed.