From 584a06f3cc6072a496436c929e4136bf3fd7ce02 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 30 Jun 2024 22:01:09 -0700 Subject: [PATCH 1/4] Report missing file when accepting snapshot This previously failed with a cryptic `error: No such file or directory (os error 2)`. It now fails with the slightly less cryptic `error: File error for '/Users/maximilian/workspace/prql/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__genre_counts.snap.new': No such file or directory (os error 2)` This happens when accepting a snapshot, which causes a watching process to re-run, which then clears pending snapshots. That process is being too aggressive about clearing pending snapshots, but that's another issue --- cargo-insta/src/container.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cargo-insta/src/container.rs b/cargo-insta/src/container.rs index 062b79c7..7c6a74cc 100644 --- a/cargo-insta/src/container.rs +++ b/cargo-insta/src/container.rs @@ -212,7 +212,10 @@ 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| { + let error = *e.downcast::().unwrap(); + ContentError::FileIo(error, self.snapshot_path.to_path_buf()) + })?; snapshot.save(&self.target_path)?; try_removing_snapshot(&self.snapshot_path); } From 33f75ba67c41df5f81de2858317bd7038b0a1373 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 30 Jun 2024 22:15:40 -0700 Subject: [PATCH 2/4] --- cargo-insta/src/container.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cargo-insta/src/container.rs b/cargo-insta/src/container.rs index 7c6a74cc..c331e1d7 100644 --- a/cargo-insta/src/container.rs +++ b/cargo-insta/src/container.rs @@ -213,6 +213,11 @@ impl SnapshotContainer { match snapshot.op { Operation::Accept => { let snapshot = Snapshot::from_file(&self.snapshot_path).map_err(|e| { + // Note that if the error isn't convertable to an + // io::Error, it'll raise a confusing error message. + // But that seems quite unlikely, and I couldn't + // find a way of handingly this without spending + // more time... let error = *e.downcast::().unwrap(); ContentError::FileIo(error, self.snapshot_path.to_path_buf()) })?; From b297d9e0330a679822e3ba7790c557c5b4987a0d Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 7 Jul 2024 12:10:00 -0700 Subject: [PATCH 3/4] --- cargo-insta/src/container.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cargo-insta/src/container.rs b/cargo-insta/src/container.rs index c331e1d7..f60fb1b0 100644 --- a/cargo-insta/src/container.rs +++ b/cargo-insta/src/container.rs @@ -213,13 +213,15 @@ impl SnapshotContainer { match snapshot.op { Operation::Accept => { let snapshot = Snapshot::from_file(&self.snapshot_path).map_err(|e| { - // Note that if the error isn't convertable to an - // io::Error, it'll raise a confusing error message. - // But that seems quite unlikely, and I couldn't - // find a way of handingly this without spending - // more time... - let error = *e.downcast::().unwrap(); - ContentError::FileIo(error, self.snapshot_path.to_path_buf()) + // If it's an IO error, pass a ContentError back so + // we get a slightly clearer error message + match e.downcast::() { + 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); From ce16de8601e9258084601ce3170f959ac113a39a Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 7 Jul 2024 12:11:44 -0700 Subject: [PATCH 4/4] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d493489..4774feea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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