refac: artifact list command with errors package#780
refac: artifact list command with errors package#780vg006 wants to merge 11 commits intogoharbor:mainfrom
artifact list command with errors package#780Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #780 +/- ##
=========================================
- Coverage 10.99% 8.61% -2.38%
=========================================
Files 173 271 +98
Lines 8671 13294 +4623
=========================================
+ Hits 953 1145 +192
- Misses 7612 12031 +4419
- Partials 106 118 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
It would be nice to also have a reference for the API handlers for that to Hint etc like how chaining would work |
cmd/harbor/root/artifact/list.go
Outdated
| projectName, repoName, err = utils.ParseProjectRepo(args[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse project/repo: %v", err) | ||
| return errors.New("Invalid project/repository format", "expected format: <project>/<repository>") |
There was a problem hiding this comment.
This and other instances of this are wrong no? since we would use the WithHint or WithMessage here instead of a new error?
There was a problem hiding this comment.
Actually, the APIs are changed a bit. WithHint is removed and merged with WithMessage which accepts the hints optionally.
In the previous style, at different layers, we could add both messages and hints optionally. So this caused issues in rendering the tree view.
Thus, I updated the WithMessage method to accept the hints optionally, but the messages aren't optional. So hints are passed only if a message is conveyed at that level.
There was a problem hiding this comment.
You can check the signature of WithMessage here
There was a problem hiding this comment.
yeah but shouldn't it still chain here, instead of returning a new one?
There was a problem hiding this comment.
That's my bad. Thanks for noting it down.
Actually for initial testing, I refactored simple errors in the artifact/list.go and this is one of such. After I refactored all returns functions that are invoked at each layer. So I forgot to replace the initial one with the actually refactored one at the primitive layer. I have updated it now.
|
@NucleoFusion The exact errors that will be returned by the API calls are quite hard to reproduce. So, if the sample tree needed to be visualized, it can be seen the in the preview of this PR #636. But the least possible demonstration is shown below, which is produced when the CLI makes API calls to Harbor instance that is down.
|
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>
Signed-off-by: vg006 <devvg006@gmail.com>
qcserestipy
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Looks very cool. I just left a few comments here and there.
| Hints []string | ||
| } | ||
|
|
||
| type Error struct { |
There was a problem hiding this comment.
I really like this package and think it is great. I wanted to note that it might be worth to document that we are shadowing the std errors package and explicitely telling people that they have to be careful about it (Like making a dedicated docs md for this).
A good way to let people do this difference could be this:
import (
stderrors "errors"
"github.com/goharbor/harbor-cli/pkg/errors"
)There was a problem hiding this comment.
Thank you for supporting my proposal. Yeah, maintaining proper documentation for this package will help maintainers and contributors to refactor either the project or the package itself. I think adding that doc to the CONTRIBUTING.md will inform the new contributors at the first place, if they work on this package or try to handle errors.
Also yeah, this package wraps the std errors, enforces to use it rather for uniformity across the codebase. Thus we could instruct the contributors to use this package instead of the std. So there will be only,
import (
"github.com/goharbor/harbor-cli/pkg/errors"
)| ) | ||
|
|
||
| const ( | ||
| GreenANSI = "\033[32m" |
There was a problem hiding this comment.
To me it looks like that those colors and styles are already defined further up. Also, there are not used anywhere.
There was a problem hiding this comment.
Yeah the styles that are declared using the lipgloss library are the ones that I introduced newly. But the hardcoded ANSI sequences were defined earlier in the project itself and removed by @NucleoFusion last month (ref). I don't know why, but I suspect an issue while rebasing. I will check it and clean it up.
| parts = append(parts, hintsTree.String()) | ||
| } | ||
|
|
||
| if len(e.frames) > 1 { |
There was a problem hiding this comment.
It would be great if you could test whether the tree structure output breaks in pipeline environments. I do not know whether all terms or envs would support this or expect single line error messages. Maybe @bupd and @NucleoFusion have some ideas, too.
There was a problem hiding this comment.
This tree output is planned to only be returned on non-verbose mode, where it's used by a real user. But for the CI and any other environment, the verbose mode of logging will be used I guess. So this tree won't be renderded, rather the error will be detailed by the logger as in the PR #722.
Even if CI or other envs use non-verbose mode, it will work I believe, because the ANSI sequences are valid UTF-8 encoded, won't disrupt tools like grep, rg parsing them, when piped the harbor output in their scripts.
For example, I tested the following in the local env to check compatibility with grep
package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
func main() {
style := lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("205")).
Padding(1)
output := style.Render("Hello, Pipeline!")
fmt.Println(output)
}Preview
|
Thank you @qcserestipy for supporting and reviewing the package. However, the above comments are very specific to the As you really interested in the betterment of this package, I really appreciate you to look into it PR #636 and will be happy to discuss further in there, will be helpful to all track relevant reviews and changes properly, that's why. Thank you. |
Isnt this PR much suited for merging? since we also get a reference material which the umbrella issue can mention and even other contributors can pick up on? I think the changes (aside from the errors package) are simple enough that we wont need to spend a lot of extra time reviewing it. |
|
Yeah @NucleoFusion,
|


Description
This PR demonstrates the implementation of the project's
pkg/errorspackage in the #636, by replacing the existing non-uniform error return statements with thepkg/errorspackage APIs.Type of Change
Changes
fmt.Errorf,errors.Newwith the built-inpkg/errorsOverview