Repository navigation
fix: clean up failed fallback downloads - #13
Conversation
Reviewer's GuideImplementationClean up both partial files when fallback startup or execution fails, stop and reap the downloader if waiting fails, and remove the redundant second wait.
TestsAdd regression coverage confirming failed fallback cleanup removes both partial files.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/fetch.rs" line_range="187" />
<code_context>
.stderr(std::process::Stdio::null())
.spawn()
- .map_err(|e| format!("could not download audio: {e}"))?;
+ {
+ Ok(child) => child,
+ Err(e) => {
</code_context>
<issue_to_address>
**Fallback branch fails to compile**
The block following `.spawn()` has no `match` keyword, so Rust rejects the fallback branch and the project cannot build.
Add `match` before the command-spawn expression.
</issue_to_address>
### Comment 2
<location path="src/fetch.rs" line_range="276-277" />
<code_context>
}
+fn cleanup_fallback(fallback: &Path, direct: &Path) {
+ let _ = std::fs::remove_file(fallback);
+ let _ = std::fs::remove_file(direct);
+}
+
</code_context>
<issue_to_address>
**Failed cleanup stays invisible**
When the filesystem refuses to remove either partial file, `remove_file` errors are discarded, so a filesystem or permission failure leaves partial downloads in the audio cache without any indication to the caller; repeated failures can consume disk space.
Surface or log cleanup failures so leftover partial files are visible and can be addressed.
</issue_to_address>
### Comment 3
<location path="src/fetch.rs" line_range="333" />
<code_context>
+ {
+ Ok(child) => child,
+ Err(e) => {
+ cleanup_fallback(&fallback, &direct);
+ return Err(format!("could not download audio: {e}"));
+ }
</code_context>
<issue_to_address>
**Fetch cleanup regressions go undetected**
When cleanup calls are removed from `fetch_async` failure paths, the direct-cleanup tests call `cleanup_fallback` rather than `fetch_async`, so they pass when spawn, wait-error, cancellation, unsuccessful-exit, or fallback-error paths stop cleaning up, leaving regressions undetected.
Exercise the relevant `fetch_async` failure paths and assert that both partial files are removed.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and if spawning or waiting for the fallback downloader fails, the change removes the fallback and direct partial-download files instead of leaving them behind. Those deletions survive a revert, but the files are failed-fetch artifacts that can be regenerated by retrying the download.
Blocking findings: src/fetch.rs:187, src/fetch.rs:277, src/fetch.rs:333
| .stderr(std::process::Stdio::null()) | ||
| .spawn() | ||
| .map_err(|e| format!("could not download audio: {e}"))?; | ||
| { |
There was a problem hiding this comment.
🔴 Critical · Fallback branch fails to compile
The block following .spawn() has no match keyword, so Rust rejects the fallback branch and the project cannot build.
Add match before the command-spawn expression.
Prompt for AI agents
In `src/fetch.rs` at line 187:
**Fallback branch fails to compile**
The block following `.spawn()` has no `match` keyword, so Rust rejects the fallback branch and the project cannot build.
Add `match` before the command-spawn expression.| let _ = std::fs::remove_file(fallback); | ||
| let _ = std::fs::remove_file(direct); |
There was a problem hiding this comment.
🟡 Medium · Failed cleanup stays invisible
When the filesystem refuses to remove either partial file, remove_file errors are discarded, so a filesystem or permission failure leaves partial downloads in the audio cache without any indication to the caller; repeated failures can consume disk space.
Surface or log cleanup failures so leftover partial files are visible and can be addressed.
Prompt for AI agents
In `src/fetch.rs` at lines 276-277:
**Failed cleanup stays invisible**
When the filesystem refuses to remove either partial file, `remove_file` errors are discarded, so a filesystem or permission failure leaves partial downloads in the audio cache without any indication to the caller; repeated failures can consume disk space.
Surface or log cleanup failures so leftover partial files are visible and can be addressed.| std::fs::write(&fallback, b"partial").unwrap(); | ||
| std::fs::write(&direct, b"partial").unwrap(); | ||
|
|
||
| cleanup_fallback(&fallback, &direct); |
There was a problem hiding this comment.
🟡 Medium · Fetch cleanup regressions go undetected
When cleanup calls are removed from fetch_async failure paths, the direct-cleanup tests call cleanup_fallback rather than fetch_async, so they pass when spawn, wait-error, cancellation, unsuccessful-exit, or fallback-error paths stop cleaning up, leaving regressions undetected.
Exercise the relevant fetch_async failure paths and assert that both partial files are removed.
Prompt for AI agents
In `src/fetch.rs` at line 333:
**Fetch cleanup regressions go undetected**
When cleanup calls are removed from `fetch_async` failure paths, the direct-cleanup tests call `cleanup_fallback` rather than `fetch_async`, so they pass when spawn, wait-error, cancellation, unsuccessful-exit, or fallback-error paths stop cleaning up, leaving regressions undetected.
Exercise the relevant `fetch_async` failure paths and assert that both partial files are removed.
Summary
Verification
Summary by Sourcery
Ensure failed fallback downloads clean up partial files and child processes reliably.
Bug Fixes:
Enhancements:
Tests: