Neptune-Crypto/neptune-core

Catch Potential Error when Trying to Find Wallet Database

Aperta

#559 aperta il 21 apr 2025

 (1 commento) (0 reazioni) (0 assegnatari)Rust (45 fork)auto 404
good first issuehelp wantedminor

Metriche repository

Star
 (110 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

See #556.

In WalletState::new_from_context:

        let database_is_new = !tokio::fs::try_exists(&data_dir.wallet_database_dir_path()).await.unwrap();

What if the path cannot be verified to exist or not exist? try_exists will return an Err case and the unwrap() will cause a panic. Let's catch that case gracefully.

I think it's preferable to catch this edge case and log a warning message. "Cannot determine existence of wallet database." Or something like that. And the variable database_is_new should be set to false so as to avoid unnecessary work.

I realize that down the line things will probably fail when the client tries to read data from the wallet database but

a) by the time control flow gets there the problem may have been resolved
b) a future refactor might find a way around that problem without affecting scan mode policy.

Guida contributor