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.
Currently, the
Displayimplementation forLoadErrordisplaysDebugoutput forLoadError::MissingDescriptorandLoadError::Mismatch:I think this is generally not a good practice.
Debugoutput is automatically generated, and is not as nice to read as a hand-writtenDisplayimplementation'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 exposesDebugoutput 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 viaDisplay.