fix(cli): remove duplicate error outputs and improve error handling
- Remove styled error prints in push/rollback commands (Cobra handles errors) - Add domain validation to Restart method to avoid bad requests - Improve rollback deploy error handling to accurately reflect revert status Changes match the pattern used in restart.go for consistency.
- commit
- 486766f3853925b1c5783fc333232d942d345aa0
- author
- brice · · 2026-02-02 18:29 UTC
- parent
- 89e85a9
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +4 -2
M internal/adapters/in/cli/push.go +0 -1
| @@ -58,7 +58,6 @@ Examples: | |||
| 58 | 58 | func runPush(ctx context.Context, pushDomain, tag string, build bool, platform string, buildArgs []string, noDeploy bool, noConfirm bool) error { | |
| 59 | 59 | client, isRemote := GetRemoteClient() | |
| 60 | 60 | if !isRemote { | |
| 61 | - | fmt.Println(styles.RenderError("push command requires --remote flag or GORDON_REMOTE env var")) | |
| 62 | 61 | return fmt.Errorf("push requires remote mode") | |
| 63 | 62 | } | |
| 64 | 63 | ||
| @@ -58,7 +58,6 @@ Examples: | |||||
| 58 | func runPush(ctx context.Context, pushDomain, tag string, build bool, platform string, buildArgs []string, noDeploy bool, noConfirm bool) error { | 58 | func runPush(ctx context.Context, pushDomain, tag string, build bool, platform string, buildArgs []string, noDeploy bool, noConfirm bool) error { | ||
| 59 | client, isRemote := GetRemoteClient() | 59 | client, isRemote := GetRemoteClient() | ||
| 60 | if !isRemote { | 60 | if !isRemote { | ||
| 61 | - | fmt.Println(styles.RenderError("push command requires --remote flag or GORDON_REMOTE env var")) | |||
| 62 | return fmt.Errorf("push requires remote mode") | 61 | return fmt.Errorf("push requires remote mode") | ||
| 63 | } | 62 | } | ||
| 64 | 63 | ||||
M internal/adapters/in/cli/remote/client.go +3 -0
| @@ -434,6 +434,9 @@ type RestartResult struct { | |||
| 434 | 434 | ||
| 435 | 435 | // Restart triggers a container restart for the specified domain. | |
| 436 | 436 | func (c *Client) Restart(ctx context.Context, restartDomain string, withAttachments bool) (*RestartResult, error) { | |
| 437 | + | if restartDomain == "" { | |
| 438 | + | return nil, fmt.Errorf("domain cannot be empty") | |
| 439 | + | } | |
| 437 | 440 | path := "/restart/" + url.PathEscape(restartDomain) | |
| 438 | 441 | if withAttachments { | |
| 439 | 442 | path += "?attachments=true" | |
| @@ -434,6 +434,9 @@ type RestartResult struct { | |||||
| 434 | 434 | ||||
| 435 | // Restart triggers a container restart for the specified domain. | 435 | // Restart triggers a container restart for the specified domain. | ||
| 436 | func (c *Client) Restart(ctx context.Context, restartDomain string, withAttachments bool) (*RestartResult, error) { | 436 | func (c *Client) Restart(ctx context.Context, restartDomain string, withAttachments bool) (*RestartResult, error) { | ||
| 437 | + | if restartDomain == "" { | |||
| 438 | + | return nil, fmt.Errorf("domain cannot be empty") | |||
| 439 | + | } | |||
| 437 | path := "/restart/" + url.PathEscape(restartDomain) | 440 | path := "/restart/" + url.PathEscape(restartDomain) | ||
| 438 | if withAttachments { | 441 | if withAttachments { | ||
| 439 | path += "?attachments=true" | 442 | path += "?attachments=true" | ||
M internal/adapters/in/cli/rollback.go +1 -1
| @@ -42,7 +42,6 @@ Examples: | |||
| 42 | 42 | func runRollback(ctx context.Context, rollbackDomain, targetTag string) error { | |
| 43 | 43 | client, isRemote := GetRemoteClient() | |
| 44 | 44 | if !isRemote { | |
| 45 | - | fmt.Println(styles.RenderError("rollback command requires --remote flag or GORDON_REMOTE env var")) | |
| 46 | 45 | return fmt.Errorf("rollback requires remote mode") | |
| 47 | 46 | } | |
| 48 | 47 | ||
| @@ -172,6 +171,7 @@ func deploySelectedTag(ctx context.Context, client *remote.Client, route *domain | |||
| 172 | 171 | route.Image = oldImage | |
| 173 | 172 | if revertErr := client.UpdateRoute(ctx, *route); revertErr != nil { | |
| 174 | 173 | fmt.Fprintf(os.Stderr, "WARNING: deploy failed and could not revert route: %v\n", revertErr) | |
| 174 | + | return fmt.Errorf("failed to deploy; revert failed: %v; deploy error: %w", revertErr, err) | |
| 175 | 175 | } | |
| 176 | 176 | return fmt.Errorf("failed to deploy (route reverted): %w", err) | |
| 177 | 177 | } | |
| @@ -42,7 +42,6 @@ Examples: | |||||
| 42 | func runRollback(ctx context.Context, rollbackDomain, targetTag string) error { | 42 | func runRollback(ctx context.Context, rollbackDomain, targetTag string) error { | ||
| 43 | client, isRemote := GetRemoteClient() | 43 | client, isRemote := GetRemoteClient() | ||
| 44 | if !isRemote { | 44 | if !isRemote { | ||
| 45 | - | fmt.Println(styles.RenderError("rollback command requires --remote flag or GORDON_REMOTE env var")) | |||
| 46 | return fmt.Errorf("rollback requires remote mode") | 45 | return fmt.Errorf("rollback requires remote mode") | ||
| 47 | } | 46 | } | ||
| 48 | 47 | ||||
| @@ -172,6 +171,7 @@ func deploySelectedTag(ctx context.Context, client *remote.Client, route *domain | |||||
| 172 | route.Image = oldImage | 171 | route.Image = oldImage | ||
| 173 | if revertErr := client.UpdateRoute(ctx, *route); revertErr != nil { | 172 | if revertErr := client.UpdateRoute(ctx, *route); revertErr != nil { | ||
| 174 | fmt.Fprintf(os.Stderr, "WARNING: deploy failed and could not revert route: %v\n", revertErr) | 173 | fmt.Fprintf(os.Stderr, "WARNING: deploy failed and could not revert route: %v\n", revertErr) | ||
| 174 | + | return fmt.Errorf("failed to deploy; revert failed: %v; deploy error: %w", revertErr, err) | |||
| 175 | } | 175 | } | ||
| 176 | return fmt.Errorf("failed to deploy (route reverted): %w", err) | 176 | return fmt.Errorf("failed to deploy (route reverted): %w", err) | ||
| 177 | } | 177 | } | ||