Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Sep 15, 2023
1 parent 3859af3 commit 7392bad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
1 change: 1 addition & 0 deletions crates/phactory/src/contracts/support/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl ContractsKeeper {
}

pub fn drain(&mut self) -> impl Iterator<Item = Contract> {
#[allow(clippy::iter_kv_map)]
std::mem::take(&mut self.contracts)
.into_iter()
.map(|(_, v)| v)
Expand Down
30 changes: 10 additions & 20 deletions crates/phactory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Phactory<Platform>
let file = File::create(&checkpoint_file).context("Failed to create checkpoint file")?;
self.take_checkpoint_to_writer(&key, file)
.context("Take checkpoint to writer failed")?;
info!("Checkpoint saved to {}", checkpoint_file);
info!("Checkpoint saved to {checkpoint_file}");
self.last_checkpoint = Instant::now();
remove_outdated_checkpoints(
&self.args.storage_path,
Expand Down Expand Up @@ -618,43 +618,33 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Phactory<Platform>
Ok(file) => file,
Err(err) if matches!(err.kind(), ErrorKind::NotFound) => {
// This should never happen unless it was removed just after the glob.
anyhow::bail!("Checkpoint file {:?} is not found", ckpt_filename);
anyhow::bail!("Checkpoint file {ckpt_filename:?} is not found");
}
Err(err) => {
error!(
"Failed to open checkpoint file {:?}: {:?}",
ckpt_filename, err
);
error!("Failed to open checkpoint file {ckpt_filename:?}: {err:?}",);
if args.remove_corrupted_checkpoint {
error!("Removing {:?}", ckpt_filename);
error!("Removing {ckpt_filename:?}");
std::fs::remove_file(ckpt_filename)
.context("Failed to remove corrupted checkpoint file")?;
}
anyhow::bail!(
"Failed to open checkpoint file {:?}: {:?}",
ckpt_filename,
err
);
anyhow::bail!("Failed to open checkpoint file {ckpt_filename:?}: {err:?}");
}
};

info!("Loading checkpoint from file {:?}", ckpt_filename);
info!("Loading checkpoint from file {ckpt_filename:?}");
match Self::restore_from_checkpoint_reader(&runtime_data.sk, file, args) {
Ok(state) => {
info!("Succeeded to load checkpoint file {:?}", ckpt_filename);
info!("Succeeded to load checkpoint file {ckpt_filename:?}");
Ok(Some(state))
}
Err(err /*Don't leak it into the log*/) => {
error!(
"Failed to load checkpoint file {:?}: {err:?}",
ckpt_filename
);
Err(_err /*Don't leak it into the log*/) => {
error!("Failed to load checkpoint file {ckpt_filename:?}");
if args.remove_corrupted_checkpoint {
error!("Removing {:?}", ckpt_filename);
std::fs::remove_file(ckpt_filename)
.context("Failed to remove corrupted checkpoint file")?;
}
anyhow::bail!("Failed to load checkpoint file {:?}", ckpt_filename);
anyhow::bail!("Failed to load checkpoint file {ckpt_filename:?}");
}
}
}
Expand Down

0 comments on commit 7392bad

Please sign in to comment.