New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(commands): use tab writer #7241
Conversation
ArtifactsThese changes are published for testing on Buildkite, DockerHub and GitHub Container Registry. Docker Container
|
WalkthroughThe recent update aims to enhance the output formatting of storage-related commands by incorporating the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
23228a0
to
60b4d93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
internal/commands/acl.go (1)
Line range hint
121-155
: Consider adding error handling fortabwriter
operations.The current implementation of
tabwriter
inaccessControlCheckWriteOutput
function ignores errors fromfmt.Fprintln
andfmt.Fprintf
methods. It's generally a good practice to handle these errors to avoid silent failures. Here's a suggested modification:- _, _ = fmt.Fprintln(w, " #\tDomain\tResource\tMethod\tNetwork\tSubject") + if _, err := fmt.Fprintln(w, " #\tDomain\tResource\tMethod\tNetwork\tSubject"); err != nil { + return fmt.Errorf("failed to write header to tabwriter: %w", err) + } - _, _ = fmt.Fprintf(w, "* %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)) + if _, err := fmt.Fprintf(w, "* %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)); err != nil { + return fmt.Errorf("failed to write applied rule to tabwriter: %w", err) + } - _, _ = fmt.Fprintf(w, "~ %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)) + if _, err := fmt.Fprintf(w, "~ %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)); err != nil { + return fmt.Errorf("failed to write potential rule to tabwriter: %w", err) + } - _, _ = fmt.Fprintf(w, " %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)) + if _, err := fmt.Fprintf(w, " %d\t%s\t%s\t%s\t%s\t%s\n", i+1, hitMissMay(result.MatchDomain), hitMissMay(result.MatchResources), hitMissMay(result.MatchMethods), hitMissMay(result.MatchNetworks), hitMissMay(result.MatchSubjects, result.MatchSubjectsExact)); err != nil { + return fmt.Errorf("failed to write default rule to tabwriter: %w", err) + } - _ = w.Flush() + if err := w.Flush(); err != nil { + return fmt.Errorf("failed to flush tabwriter: %w", err) + }This change ensures that any issues during the writing process are caught and handled appropriately.
60b4d93
to
ee773d3
Compare
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
ee773d3
to
763a008
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7241 +/- ##
=======================================
Coverage 73.68% 73.68%
=======================================
Files 346 346
Lines 29986 30003 +17
Branches 839 839
=======================================
+ Hits 22095 22109 +14
- Misses 7019 7020 +1
- Partials 872 874 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Summary by CodeRabbit