Skip to content

Display implementations should not expose Debug output #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
casey opened this issue Mar 3, 2025 · 2 comments
Open

Display implementations should not expose Debug output #1933

casey opened this issue Mar 3, 2025 · 2 comments
Labels
good first issue Good for newcomers

Comments

@casey
Copy link

casey commented Mar 3, 2025

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.

@Yashvardhan24
Copy link

Hello, is this issue available to work on?

@ValuedMammal
Copy link
Contributor

For anyone following there is a PR in progress #1881 that addresses the issue in bdk_wallet. Check this comment #1881 (comment) for an idea of what remains to be fixed.

@notmandatory notmandatory transferred this issue from bitcoindevkit/bdk Apr 7, 2025
@notmandatory notmandatory removed this from BDK Wallet Apr 7, 2025
@notmandatory notmandatory transferred this issue from bitcoindevkit/bdk_wallet Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: Todo
3 participants