Skip to content

Commit

Permalink
fix: error mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Crayon Shin-chan committed Sep 23, 2024
1 parent e3bb8e3 commit 8d25b84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ commit_verify = { workspace = true }
bp-seals = { workspace = true }
bp-std = { workspace = true, features = ["serde"] }
bp-wallet = { workspace = true, features = ["cli"] }
nonasync = { workspace = true }
psbt = { workspace = true }
rgb-std = { workspace = true, features = ["serde"] }
rgb-interfaces = { workspace = true }
Expand Down
21 changes: 13 additions & 8 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::path::PathBuf;
use bpstd::{Wpkh, XpubDerivable};
use bpwallet::cli::{Args as BpArgs, Config, DescriptorOpts};
use bpwallet::Wallet;
use nonasync::persistence::PersistenceError;
use rgb::persistence::Stock;
use rgb::resolvers::AnyResolver;
use rgb::{RgbDescr, RgbWallet, TapretKey, WalletError};
Expand Down Expand Up @@ -105,15 +106,19 @@ impl RgbArgs {

let provider = FsBinStore::new(stock_path.clone())?;
let mut stock = Stock::load(provider, true).map_err(WalletError::WalletPersist).or_else(|err| {
if matches!(err, WalletError::Deserialize(DeserializeError::Decode(DecodeError::Io(ref err))) if err.kind() == ErrorKind::NotFound) {
if self.verbose > 1 {
eprint!("stock file is absent, creating a new one ... ");
if let WalletError::WalletPersist(PersistenceError(ref err)) = err {
if let Some(DeserializeError::Decode(DecodeError::Io(io_err))) = err.downcast_ref::<DeserializeError>() {
if io_err.kind() == ErrorKind::NotFound {
if self.verbose > 1 {
eprint!("stock file is absent, creating a new one ... ");
}
fs::create_dir_all(&stock_path)?;
let provider = FsBinStore::new(stock_path)?;
let mut stock = Stock::in_memory();
stock.make_persistent(provider, true).map_err(WalletError::StockPersist)?;
return Ok(stock);
}

Check warning on line 120 in cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L109-L120

Added lines #L109 - L120 were not covered by tests
}
fs::create_dir_all(&stock_path)?;
let provider = FsBinStore::new(stock_path)?;
let mut stock = Stock::in_memory();
stock.make_persistent(provider, true).map_err(WalletError::StockPersist)?;
return Ok(stock);
}
eprintln!("stock file is damaged, failing");
Err(err)
Expand Down

0 comments on commit 8d25b84

Please sign in to comment.