-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[logging] Adds a method for using specific messaging for known errors
- Loading branch information
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package logging | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// knownErrorPatterns Returns list of all known error patterns | ||
func knownErrorPatterns() []string { | ||
return []string{ | ||
"error dialing DHCP daemon", | ||
} | ||
} | ||
|
||
// getKnownErrorMessage returns | ||
func getKnownErrorMessage(patternkey string) (string, error) { | ||
messages := map[string]string{ | ||
"error dialing DHCP daemon": "Please check that the DHCP CNI daemon is running and is properly configured.", | ||
} | ||
|
||
if val, ok := messages[patternkey]; ok { | ||
return val, nil | ||
} | ||
|
||
return "", fmt.Errorf("Known error key '" + patternkey + "' does not have a message") | ||
|
||
} | ||
|
||
// detectKnownErrors detects the first known error given n number of stringers as passed to the logging methods | ||
func addKnownErrorMessage(a ...interface{}) string { | ||
var knownerrormessage string | ||
knownerrors := knownErrorPatterns() | ||
|
||
knownerrorloop: | ||
for _, eachstringer := range a { | ||
for _, eachknownerror := range knownerrors { | ||
if strings.Contains(fmt.Sprintf("%s", eachstringer), eachknownerror) { | ||
knownerrormessage, _ = getKnownErrorMessage(eachknownerror) | ||
knownerrormessage = " (" + knownerrormessage + ") " | ||
break knownerrorloop | ||
} | ||
} | ||
} | ||
return knownerrormessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters