feat: added functionality to delete failed, completed, all downloads from cli tui and extension#479
Open
junaid2005p wants to merge 11 commits into
Open
feat: added functionality to delete failed, completed, all downloads from cli tui and extension#479junaid2005p wants to merge 11 commits into
junaid2005p wants to merge 11 commits into
Conversation
Binary Size Analysis
|
Comment on lines
+664
to
+667
| result, err := db.Exec("DELETE FROM downloads WHERE status = 'failed'") | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to remove failed downloads") | ||
| } |
Contributor
There was a problem hiding this comment.
The underlying database error from
db.Exec is discarded. RemoveCompletedDownloads (the sibling function) uses %w to wrap the error, but this function drops it, making it impossible for callers to inspect or unwrap the root cause.
Suggested change
| result, err := db.Exec("DELETE FROM downloads WHERE status = 'failed'") | |
| if err != nil { | |
| return 0, fmt.Errorf("failed to remove failed downloads") | |
| } | |
| result, err := db.Exec("DELETE FROM downloads WHERE status = 'failed'") | |
| if err != nil { | |
| return 0, fmt.Errorf("failed to remove failed downloads: %w", err) | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/engine/state/state.go
Line: 664-667
Comment:
The underlying database error from `db.Exec` is discarded. `RemoveCompletedDownloads` (the sibling function) uses `%w` to wrap the error, but this function drops it, making it impossible for callers to inspect or unwrap the root cause.
```suggestion
result, err := db.Exec("DELETE FROM downloads WHERE status = 'failed'")
if err != nil {
return 0, fmt.Errorf("failed to remove failed downloads: %w", err)
}
```
How can I resolve this? If you propose a fix, please make it concise.
Comment on lines
+54
to
+58
| //Clear completed downloads from surge | ||
| ClearCompleted() (int64, error) | ||
|
|
||
| //Clear failed downloads from surge | ||
| ClearFailed() (int64, error) |
Contributor
There was a problem hiding this comment.
Go convention requires a space after
// in single-line comments, and doc comments on exported/interface methods should follow the // MethodName ... format used elsewhere in this file.
Suggested change
| //Clear completed downloads from surge | |
| ClearCompleted() (int64, error) | |
| //Clear failed downloads from surge | |
| ClearFailed() (int64, error) | |
| // ClearCompleted removes all completed downloads and returns the count deleted. | |
| ClearCompleted() (int64, error) | |
| // ClearFailed removes all failed downloads and returns the count deleted. | |
| ClearFailed() (int64, error) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/core/interface.go
Line: 54-58
Comment:
Go convention requires a space after `//` in single-line comments, and doc comments on exported/interface methods should follow the `// MethodName ...` format used elsewhere in this file.
```suggestion
// ClearCompleted removes all completed downloads and returns the count deleted.
ClearCompleted() (int64, error)
// ClearFailed removes all failed downloads and returns the count deleted.
ClearFailed() (int64, error)
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
87ac453 to
641d6d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greptile Summary
This PR adds the ability to delete failed downloads alongside the existing completed-download cleanup, wiring the feature through the CLI (
surge rm --clean-failed), HTTP API (/clear-failed), local service, and remote service.cmd/rm.goadds a--clean-failedflag and a correspondingelse ifbranch, while correctly extending the empty-args guard — but two flag-combination edge cases are unguarded (see inline comments).internal/engine/state/state.goaddsRemoveFailedDownloads, which mirrorsRemoveCompletedDownloadsexcept that the underlying DB error is not wrapped with%w, preventing callers from unwrapping the root cause.DownloadServiceinterface, local service, remote service, and HTTP routes are updated consistently; all test fixtures are updated to satisfy the new interface methods.Confidence Score: 3/5
The CLI flag-combination logic in cmd/rm.go has two gaps that cause silent misbehaviour before the fix lands.
Both --clean --clean-failed (second flag silently ignored) and --clean-failed --purge (purge never executed, potentially leaving orphaned partial files) are defects introduced by this PR that need to be addressed before merging.
cmd/rm.go — the flag-combination guards are incomplete.
Important Files Changed
--clean-failedflag and handler; guard for empty args is correctly updated, but two logic gaps remain:--clean --clean-failedsilently ignoresclean_failed, and--clean-failed --purgesilently ignorespurge.RemoveFailedDownloadsmirroringRemoveCompletedDownloads; the underlying DB error is not wrapped with%w(unlike the sibling function), which was already flagged in a previous review thread.ClearCompletedandClearFailedtoDownloadServiceinterface; comment style is missing the standard Go doc format (already noted in previous thread).ClearCompletedandClearFailedvia the existingdoRequestpattern; error handling and response decoding are consistent with sibling methods./clear-completedand/clear-failedPOST endpoints; follows the existing handler pattern correctly.Comments Outside Diff (2)
cmd/rm.go, line 17-39 (link)--clean-failedflag is registered but never handledThe
clean-failedflag is added ininit()but theRunEbody never reads it. Runningsurge rm --clean-failedwith no positional argument hits the!clean && len(args) == 0branch and returns"provide a download ID or use --clean", silently ignoring the user's intent. The flag is effectively dead code.Prompt To Fix With AI
cmd/rm.go, line 25-27 (link)--clean-failedguard never checkedThe early-exit condition
!clean && len(args) == 0does not account forclean_failed, sosurge rm --clean-failed(no positional arg) exits with "provide a download ID or use --clean" before ever reaching theelse if clean_failedbranch. The flag is effectively unreachable without also supplying an ID that is then ignored.The condition should also allow the
clean-failedflag through:!clean && !cleanFailed && len(args) == 0.Prompt To Fix With AI
Reviews (6): Last reviewed commit: "fix: clean-failed guard in rm command" | Re-trigger Greptile
Context used: