fix(replication/retention): propagate prompt and view errors to prevent abrupt CLI crashes#932
Conversation
Refactored the replication prompt handlers (GetReplicationPolicyFromUser, GetReplicationExecutionIDFromUser, GetReplicationTaskIDFromUser) to return (int64, error) instead of using log.Fatal(). Updated all replication-related commands to handle these errors and bubble them up via Cobra's RunE, ensuring consistent, automation-friendly exit codes instead of abrupt process termination. Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #932 +/- ##
=========================================
- Coverage 10.99% 9.30% -1.69%
=========================================
Files 173 314 +141
Lines 8671 15823 +7152
=========================================
+ Hits 953 1473 +520
- Misses 7612 14215 +6603
- Partials 106 135 +29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I’ve pushed a larger round of updates after additional verification of the replication and tag retention flows. The changes now address several related issues around:
One important fix here was preventing cancelled selection prompts from unintentionally proceeding with default rule indices during tag retention deletion flows. The updated implementation now consistently bubbles errors/cancellations back through Cobra instead of terminating inside prompt/view helpers. Would appreciate your feedback/review whenever you have time. Thanks! |
2d4f05d to
bc31de4
Compare
|
@gcharpe1604 Thank you for your contribution. However, this PR addresses much more changes than the connected issue. Please reduce this PR to the mentioned changes in the issue. For other changes open a new issue and related PRs. |
|
@qcserestipy I had university end-semester exams over the last week and wasn't able to spend time on the PR. I'm reviewing the feedback now and re-evaluating the scope based on your comments. I'll reduce the PR so it stays focused on the issue being addressed. The broader prompt/view improvements and related changes can be proposed separately where appropriate to keep the review scope manageable. |
…and bugs Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
bc31de4 to
0ca5b5c
Compare
…vent abrupt CLI crashes Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
…mpt-error-handling Signed-off-by: Govind Charpe <govind.charpe16@gmail.com> # Conflicts: # pkg/prompt/prompt.go
|
Hi @qcserestipy, I've updated the PR based on the review feedback and reduced the scope to focus on the issue in #931. The current changes are limited to removing the direct I've also removed the unrelated changes from this branch to keep the review focused. Could you take another look when you get a chance? Thanks!! |
Description
This PR fixes replication interactive prompt helpers and views that terminate the CLI abruptly via
log.Fatal()oros.Exit(1)during API failures or invalid selections.Errors are now propagated through Cobra's command lifecycle (
RunE) instead of terminating the process directly, resulting in more consistent and automation-friendly CLI behavior.Fixes #931
Type of Change
Key Changes in PR #932
1. Removal of Abrupt CLI Crashes (
log.Fatal(),os.Exit())log.Fatal()in prompt helper functions inpkg/prompt/prompt.gowhen replication APIs fail or return empty lists.os.Exit(1)calls inside selection views (such asReplicationExecutionListandReplicationTasksList) with clean error propagation via channels.2. Error & Cancel/Abort Propagation
errChan chan<- errorchannel to the asynchronous view functions to propagate errors back to the caller prompts.os.Exit(1).How to Test
Verify Cancel/Abort Graceful Exit:
Run an interactive command like
harbor replication startwithout arguments, cancel the prompt selection, and verify the command exits gracefully withuser aborted selectioninstead of callinglog.Fatal(), callingos.Exit(1), or silently executing on default values.Replication Commands:
Verify
harbor replication start,harbor replication stop, andharbor replication logfunction as expected and terminate cleanly if aborted.