Skip to content

Commit

Permalink
Don't panic when timestamp file is not found (fix #117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Expurple authored and marcospb19 committed Mar 27, 2024
1 parent e1761a4 commit 5075756
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ fn main() -> anyhow::Result<()> {
}
} else {
let keep_duration = if let Criterion::File = criterion {
let ts = Timestamp::load(paths[0].as_path(), dry_run)
.expect("Failed to load timestamp file");
let ts = Timestamp::load(paths[0].as_path(), dry_run)?;
Duration::from(ts)
} else if let Criterion::Time(days_to_keep) = criterion {
Duration::from_secs(days_to_keep * 24 * 3600)
Expand Down
11 changes: 11 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ fn error_status() -> TestResult {
Ok(())
}

/// This scenario used to panic: https://github.com/holmgr/cargo-sweep/issues/117
#[test]
fn stamp_file_not_found() -> TestResult {
sweep(&["--file"])
.current_dir(test_dir().join("sample-project"))
.assert()
.failure()
.stderr(contains("failed to read stamp file").and(contains("panicked").not()));
Ok(())
}

#[test]
fn path() -> TestResult {
let (_, target) = build("sample-project")?;
Expand Down

0 comments on commit 5075756

Please sign in to comment.