feat(pkg): Add package errors for the CLI#636
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #636 +/- ##
=========================================
- Coverage 10.99% 9.58% -1.41%
=========================================
Files 173 282 +109
Lines 8671 14119 +5448
=========================================
+ Hits 953 1354 +401
- Misses 7612 12639 +5027
- Partials 106 126 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
func (e *Error) Error() string {
if len(e.frames) == 0 {
return ""
}
return e.frames[len(e.frames)-1].Message
}Are we not supposed to play around this? type error interface {
Error() string
}Cobra calls the My attempt at invoking an errory := errors.Newf("%s", "testing errors").WithHint("Try rm -rf").WithCause(errors.New("suicide"))
return errors.Wrap(y, "checking wrap")This returns an error (when using I believe it should include the Cause, All frames, and hints / messages |
|
@NucleoFusion For more info, here are the package doc and an example of what I mean.
Of course we can modify the
But now, if we aren't going with custom log handlers and delegate the error handling to Hope this clarifies your doubts regarding the current implementation. I will do the needful changes and update the PR, so that I will start the refactoring of commands in favor of #635 and #717, once these get into the upstream. |
|
I dont think we will be switching to a custom handler or using Of course, you can add formats such that when cause or frames or hints are nil, they get ignored and stuff. |
|
Also, just for clarification |
|
The I just added those for conventions and So yeah, we can remove them and update the methods accordingly. |
c1b9248 to
b360aca
Compare
|
@cubic-dev-ai review |
There was a problem hiding this comment.
Pull request overview
Introduces a dedicated pkg/errors package to standardize CLI error construction and rendering (including codes, causes, hints, and chained messages), addressing inconsistent/poor error reporting discussed in #635.
Changes:
- Added
pkg/errorswith a framed error type, wrapping helpers, and formatted output usinglipgloss/tree. - Added unit tests covering construction, wrapping, hints, frames, and helpers (
Cause,Hints,Status). - Added new
lipglossstyles inpkg/viewsto support consistent error formatting.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/views/styles.go | Adds new error-specific lipgloss styles used by the new error renderer. |
| pkg/errors/utils.go | Adds Harbor error message/code extraction helpers used for Cause and Code rendering. |
| pkg/errors/errors.go | Adds the core Error type (frames, cause, rendering, wrappers, helper functions). |
| pkg/errors/errors_test.go | Adds comprehensive tests for the new pkg/errors behavior and formatting expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@vg006 resolve copilot reviews and also rebase the pr. Thanks |
|
Sure, I’m currently out of town. I’ll review the changes and update the branch shortly. |
|
@bupd |
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
|
I request you to halt the merge for a while, currently making some iterations over it and will complete them soon. Will be there to explain them in the upcoming community meeting. Thank you. |
Overview
Fixes #635.
This PR aims to provide the solution, as proposed & discussed in the issue. So as an initiative, the errors package is defined.
The layout of the error message is as follows.
Preview