-
Notifications
You must be signed in to change notification settings - Fork 72
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
None of the error returned by reporters are checked #134
Comments
I added a new pull request. I did some refactoring on cli.go can you look it? |
Can you reference the link? Because I looked for it and didn't see it. |
|
I like the refactoring you initiated, but it doesn't address the issue I raised here Please look at this config-file-validator/pkg/cli/cli.go Lines 137 to 141 in e9d7f48
Either and the error are not tested. Your code is now simpler, so it's good, but you should consider something like this if len(GroupOutput) == 1 && GroupOutput[0] != "" {
// Check reporter type to determine how to print
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
err = reporter.PrintSingleGroupJson(reportGroup.(map[string][]reporter.Report))
} else {
err = reporter.PrintSingleGroupStdout(reportGroup.(map[string][]reporter.Report))
}
} else if len(GroupOutput) == 2 {
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
err = reporter.PrintDoubleGroupJson(reportGroup.(map[string]map[string][]reporter.Report))
} else {
err = reporter.PrintDoubleGroupStdout(reportGroup.(map[string]map[string][]reporter.Report))
}
} else if len(GroupOutput) == 3 {
if _, ok := c.Reporter.(reporter.JsonReporter); ok {
err = reporter.PrintTripleGroupJson(reportGroup.(map[string]map[string]map[string][]reporter.Report))
} else {
err = reporter.PrintTripleGroupStdout(reportGroup.(map[string]map[string]map[string][]reporter.Report))
}
} else {
err = c.Reporter.Print(reports)
}
if err != nil {
return err
}
return nil |
Yeah I will return the error. Thanks for the suggestion. |
Instead of err = reporter.PrintSingleGroupJson(reportGroup.(map[string][]reporter.Report)) Can't we use return reporter.PrintSingleGroupJson(reportGroup.(map[string][]reporter.Report)) |
You refactored it the right way. I mean the current version is already applying the pattern you talked about. So you solved the issue with #131 now, which is great. I will comment the other PR then, because I have a code suggestion |
In pkg/cli/cli.go there is a section where none of the
reporter.Print*
method that could return errors are checkedconfig-file-validator/pkg/cli/cli.go
Lines 116 to 141 in 54b6781
This code requires a bit of refactoring, I think.
The addition of quiet mode (great addition BTW) with #124 made it even more complex to read and maintain.
The text was updated successfully, but these errors were encountered: