Skip to content

Fix duplicate error output and improve error handling#16

Merged
meap merged 2 commits intomainfrom
fix/duplicate-error-output
Aug 16, 2025
Merged

Fix duplicate error output and improve error handling#16
meap merged 2 commits intomainfrom
fix/duplicate-error-output

Conversation

@meap
Copy link
Copy Markdown
Owner

@meap meap commented Aug 16, 2025

Summary

  • Fixed duplicate error messages that were appearing in CLI output
  • Replaced all log.Fatal calls with proper error returns for consistent error handling
  • Improved error propagation throughout the command structure

Changes

Error Output Fix

  • Removed duplicate error wrapping in GetClusters function that was causing "failed to list clusters" to appear twice
  • Eliminated redundant fmt.Println(err) in Execute() function - Cobra already handles error output

Error Handling Improvements

  • Converted all command handlers from Run to RunE to support error returns
  • Replaced all log.Fatal* calls with fmt.Errorf and proper error returns
  • Updated parseServiceFlag to return errors instead of calling log.Fatal
  • Added error handling for parseServiceFlag in all command handlers

Test Plan

  • Verified error messages appear only once when commands fail
  • Tested invalid service name format shows proper error
  • Tested missing required flags show proper errors
  • Ran go fmt and go vet - no issues
  • Verified no remaining log.Fatal calls in cmd package

Summary by CodeRabbit

  • New Features
    • Added graceful cancellation via Ctrl+C for run, prune, restart, and revisions commands.
  • Bug Fixes
    • Prevented abrupt termination on failures; commands now return clear errors and proper exit codes.
    • Improved consistency of success and status output across commands.
  • Refactor
    • Unified error handling across commands, replacing fatal exits with propagated errors.
    • Standardized command execution to support error-returning handlers.
    • Enhanced argument/flag validation with explicit error feedback.

meap added 2 commits August 16, 2025 17:43
- Remove duplicate error wrapping in GetClusters function
- Remove redundant fmt.Println(err) in Execute function
- Let Cobra handle error output to avoid duplication
- Update parseServiceFlag to return error instead of log.Fatal
- Convert all command handlers from Run to RunE
- Replace log.Fatal calls with fmt.Errorf and error returns
- Update all commands: restart, deploy, prune, revisions, run, completion
- Ensure consistent error handling across the codebase
- Update parseServiceFlag callers to handle returned errors
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 16, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Commands in cmd/* switch from Run to RunE, converting handlers to return errors and replacing log.Fatalf with error propagation. parseServiceFlag now returns (cluster, service, error). Several commands add signal-aware contexts. main.go updates Execute handling. internal/ecs/list.go simplifies error return in GetClusters.

Changes

Cohort / File(s) Summary
Cobra Run→RunE and error propagation
cmd/completion.go, cmd/deploy.go, cmd/prune.go, cmd/restart.go, cmd/revisions.go, cmd/run.go
Replace Run with RunE; handlers return error; switch log.Fatalf to fmt.Errorf with wrapping; add explicit return nil on success. prune, restart, revisions, run introduce signal.NotifyContext for cancellation.
Service flag parsing and execution entrypoint
cmd/main.go
parseServiceFlag signature changed to (string, string, error); returns descriptive errors instead of fatal logs. On rootCmd.Execute() error, exit with status 1 without printing. Remove unused log import.
ECS list error handling
internal/ecs/list.go
GetClusters returns underlying error directly (removes additional fmt.Errorf context). No signature changes.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant Command as Cobra Command (RunE)
  participant AWS as AWS/ECS Client

  User->>CLI: run/prune/restart/revisions/deploy/completion
  CLI->>Command: Execute()
  Command->>Command: parseServiceFlag() → (cluster, service, err)
  alt err != nil
    Command-->>CLI: return err
    CLI-->>User: exit code 1
  else
    Command->>AWS: init client / perform operation
    alt operation error
      Command-->>CLI: return err (wrapped)
      CLI-->>User: exit code 1
    else
      Command-->>CLI: return nil
      CLI-->>User: success output
    end
  end
Loading
sequenceDiagram
  participant User
  participant Command as Command RunE
  participant Signal as OS Signals
  participant Ctx as Context (signal.NotifyContext)
  participant AWS as AWS/ECS Ops

  Command->>Ctx: create cancelable context
  Signal-->>Ctx: SIGINT/SIGTERM → cancel()
  Command->>AWS: call ops with ctx
  alt ctx canceled or error
    AWS-->>Command: error
    Command-->>User: return error (propagated)
  else
    AWS-->>Command: result
    Command-->>User: print status, return nil
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A rabbit taps the RunE key,
Let errors hop back, clean and free.
Signals whisper, “time to flee,”
Context cancels gracefully.
Flags now parse with honesty—
We burrow neat through ECS,
And surface with serenity. 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.2.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c18f0f5 and 0776103.

📒 Files selected for processing (8)
  • cmd/completion.go (3 hunks)
  • cmd/deploy.go (2 hunks)
  • cmd/main.go (1 hunks)
  • cmd/prune.go (4 hunks)
  • cmd/restart.go (3 hunks)
  • cmd/revisions.go (3 hunks)
  • cmd/run.go (4 hunks)
  • internal/ecs/list.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/duplicate-error-output

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@meap meap merged commit e7d909b into main Aug 16, 2025
1 check was pending
@meap meap deleted the fix/duplicate-error-output branch August 16, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant