Skip to content

Commit

Permalink
Improve error message on file write error (mitsuhiko#631)
Browse files Browse the repository at this point in the history
Will help to diagnose mitsuhiko#621
  • Loading branch information
max-sixty authored Oct 1, 2024
1 parent 9c75613 commit 916eed7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 0 additions & 2 deletions insta/src/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub enum Error {
UnexpectedDataType,
#[cfg(feature = "_cargo_insta_internal")]
MissingField,
#[cfg(feature = "_cargo_insta_internal")]
FileIo(std::io::Error, std::path::PathBuf),
}

Expand All @@ -39,7 +38,6 @@ impl fmt::Display for Error {
}
#[cfg(feature = "_cargo_insta_internal")]
Error::MissingField => f.write_str("A required field was missing"),
#[cfg(feature = "_cargo_insta_internal")]
Error::FileIo(e, p) => {
f.write_str(format!("File error for {:?}: {}", p.display(), e).as_str())
}
Expand Down
3 changes: 2 additions & 1 deletion insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ impl Snapshot {
}

let serialized_snapshot = self.serialize_snapshot(md);
fs::write(path, serialized_snapshot)?;
fs::write(path, serialized_snapshot)
.map_err(|e| content::Error::FileIo(e, path.to_path_buf()))?;
Ok(())
}

Expand Down

0 comments on commit 916eed7

Please sign in to comment.