Skip to content

Commit

Permalink
Merge pull request #516 from max-sixty/report-file-error
Browse files Browse the repository at this point in the history
Report missing file when accepting snapshot
  • Loading branch information
max-sixty authored Jul 7, 2024
2 parents d5ff35f + ce16de8 commit 116704d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to insta and cargo-insta are documented here.

## 1.40.0

- Print a clearer error message when accepting a snapshot that was removed. #516

## 1.39.0

- Fixed a bug in `require_full_match`. #485
Expand Down
12 changes: 11 additions & 1 deletion cargo-insta/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,17 @@ impl SnapshotContainer {
for snapshot in self.snapshots.iter() {
match snapshot.op {
Operation::Accept => {
let snapshot = Snapshot::from_file(&self.snapshot_path)?;
let snapshot = Snapshot::from_file(&self.snapshot_path).map_err(|e| {
// If it's an IO error, pass a ContentError back so
// we get a slightly clearer error message
match e.downcast::<std::io::Error>() {
Ok(io_error) => Box::new(ContentError::FileIo(
*io_error,
self.snapshot_path.to_path_buf(),
)),
Err(other_error) => other_error,
}
})?;
snapshot.save(&self.target_path)?;
try_removing_snapshot(&self.snapshot_path);
}
Expand Down

0 comments on commit 116704d

Please sign in to comment.