Skip to content

Commit

Permalink
Update cli/src/args.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Dr. Maxim Orlovsky <[email protected]>
  • Loading branch information
2 people authored and Crayon Shin-chan committed Oct 7, 2024
1 parent 2481c5f commit 2b2042d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,32 @@ impl RgbArgs {

let provider = FsBinStore::new(stock_path.clone())?;
let mut stock = Stock::load(provider, true)
.map_err(WalletError::WalletPersist)
.or_else(|err| {
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);
}
let Some(DeserializeError::Decode(DecodeError::Io(io_err))) =
err.0.downcast_ref::<DeserializeError>()

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L108-L111

Added lines #L108 - L111 were not covered by tests
else {
eprintln!("stock file is damaged, failing");
return Err(err);

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L113-L114

Added lines #L113 - L114 were not covered by tests
};

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)
.map_err(|err| PersistenceError(Box::new(err)))?;
let provider = FsBinStore::new(stock_path)
.map_err(|err| PersistenceError(Box::new(err)))?;
let mut stock = Stock::in_memory();
stock
.make_persistent(provider, true)
.map_err(|err| PersistenceError(Box::new(err)))?;
return Ok(stock);

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L117-L129

Added lines #L117 - L129 were not covered by tests
}
eprintln!("stock file is damaged, failing");
Err(err)
})?;
})
.map_err(WalletError::WalletPersist)?;

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

View check run for this annotation

Codecov / codecov/patch

cli/src/args.rs#L131-L134

Added lines #L131 - L134 were not covered by tests

if self.sync {
let resolver = self.resolver()?;
Expand Down

0 comments on commit 2b2042d

Please sign in to comment.