Skip to content

refactor(cli): improve root command error handling with idiomatic RunE pattern#323

Open
Harishrs2006 wants to merge 1 commit intomicrocks:masterfrom
Harishrs2006:refactor/cmd-stop-graceful-errors
Open

refactor(cli): improve root command error handling with idiomatic RunE pattern#323
Harishrs2006 wants to merge 1 commit intomicrocks:masterfrom
Harishrs2006:refactor/cmd-stop-graceful-errors

Conversation

@Harishrs2006
Copy link
Copy Markdown

@Harishrs2006 Harishrs2006 commented May 7, 2026

Description:
This pull request introduces an incremental refactor of the CLI command execution model to improve error handling consistency and align with idiomatic Go and Cobra best practices.

The changes focus on migrating the root command from Run to RunE and improving error propagation by removing direct errors.CheckError() usage.

Key improvements:

  • Migrated root command execution from Run to RunE
  • Removed abrupt termination patterns using errors.CheckError()
  • Introduced proper error propagation using return error
  • Ensured errors are wrapped using fmt.Errorf("%w") where applicable
  • Enabled SilenceErrors to avoid duplicate Cobra error output
  • Maintained backward-compatible CLI behavior
  • Improved testability of command execution flow

This refactor does not introduce breaking changes and is designed as a safe incremental improvement to the CLI architecture.

Benefits

  • Improves testability of CLI commands
  • Enables proper error propagation through Cobra command chain
  • Aligns CLI design with standard tools like kubectl and docker CLI
  • Makes future command extensions safer and cleaner
  • Reduces reliance on process termination patterns (os.Exit style behavior)

Notes:
This is part of an incremental migration strategy. Additional commands will be refactored in subsequent PRs following the same pattern.

Fixes: #322

Signed-off-by: Harish R S <harishrs21082006@gmail.com>
@Harishrs2006 Harishrs2006 force-pushed the refactor/cmd-stop-graceful-errors branch from 3b624f7 to d74a5f1 Compare May 7, 2026 19:26
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.

Refactor CLI error handling to idiomatic Cobra RunE pattern for improved testability and maintainability

1 participant