Skip to content
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

[logging] Adds a method for using specific messaging for known errors #517

Closed

Conversation

dougbtv
Copy link
Member

@dougbtv dougbtv commented Jun 9, 2020

This introduces a new set of "known errors" -- a series of known errors that may occur, especially related to usage.

The goal is to add some actionable instructions for users when they encounter something that we know to occur with some frequency. In this case, we start with a single known error -- that error being when the DHCP CNI daemon isn't running the DHCP IPAM CNI plugin returns an error stating so much. Here, we instruct the user to make sure the DHCP CNI daemon is running.

The downside is that this makes the error messages even longer for the time being. However, I'm hopeful that in the future this makes for a way to shorten at least some known error messages.

@dougbtv dougbtv requested a review from s1061123 June 9, 2020 18:58
@coveralls
Copy link

coveralls commented Jun 9, 2020

Pull Request Test Coverage Report for Build 138755272

  • 21 of 23 (91.3%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.0%) to 72.523%

Changes Missing Coverage Covered Lines Changed/Added Lines %
logging/known_errors.go 21 23 91.3%
Totals Coverage Status
Change from base Build 138076903: 1.0%
Covered Lines: 1098
Relevant Lines: 1514

💛 - Coveralls

Copy link
Member

@s1061123 s1061123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good to me. Add minor comments, so could you please take a look into it?

@@ -0,0 +1,45 @@
package logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need to have copyright as multus/multus.go

"strings"
)

// knownErrorPatterns Returns list of all known error patterns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about to use variable instead of function?

var knownErrorPatterns = []string{
    "error dialing DHCP daemon",
}

for _, eachstringer := range a {
for _, eachknownerror := range knownerrors {
if strings.Contains(fmt.Sprintf("%s", eachstringer), eachknownerror) {
knownerrormessage, _ = getKnownErrorMessage(eachknownerror)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about to add error handling for getKnownErrorMessage() because getKnownErrorMessage() returns error.

return val, nil
}

return "", fmt.Errorf("Known error key '" + patternkey + "' does not have a message")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be use lower case for error message

https://github.com/golang/go/wiki/CodeReviewComments#error-strings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to fix

if strings.Contains(fmt.Sprintf("%s", eachstringer), eachknownerror) {
knownerrormessage, _ = getKnownErrorMessage(eachknownerror)
knownerrormessage = " (" + knownerrormessage + ") "
break knownerrorloop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use continue instead of break?

@dougbtv
Copy link
Member Author

dougbtv commented Jun 17, 2020

Thank you very much for the thorough review! Quite helpful. I have a new commit up to address it 👍

@github-actions
Copy link

github-actions bot commented Apr 4, 2021

This pull request is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 4, 2021
@github-actions github-actions bot closed this Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants