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

analyzer:bugfix - separate warnings from errors #1013

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/controllers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (a *Analyzer) setVulnerabilityType(
func (a *Analyzer) setAnalysisFinishedData() *analysis.Analysis {
a.analysis.FinishedAt = time.Now()

a.removeWarningsFromErrors()
if a.analysis.HasErrors() {
a.analysis.Status = enumsAnalysis.Error
return a.analysis
Expand Down Expand Up @@ -430,3 +431,26 @@ func (a *Analyzer) getAllConfigHashes() []string {

return configHashes
}

// removeWarningsFromErrors workaround to separate warnings from errors until the formatters are refactored
func (a *Analyzer) removeWarningsFromErrors() {
var errors string

for _, err := range strings.SplitAfter(a.analysis.Errors, ";") {
if a.isWarning(err) {
a.analysis.AddWarning(err)
} else {
errors += err
}
}

a.analysis.Errors = errors
}

// isWarning workaround to check if the message it's form a warning until the formatters are refactored
func (a *Analyzer) isWarning(err string) bool {
return strings.Contains(err, messages.MsgErrorPacketJSONNotFound) ||
strings.Contains(err, messages.MsgErrorYarnLockNotFound) ||
strings.Contains(err, messages.MsgErrorGemLockNotFound) ||
strings.Contains(err, messages.MsgErrorNotFoundRequirementsTxt)
}
12 changes: 2 additions & 10 deletions internal/controllers/printresults/print_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,8 @@ func (pr *PrintResults) checkIfExistsErrorsInAnalysis() {
}
}

func (pr *PrintResults) printErrors(errorMessage string) {
if strings.Contains(errorMessage, messages.MsgErrorPacketJSONNotFound) ||
strings.Contains(errorMessage, messages.MsgErrorYarnLockNotFound) ||
strings.Contains(errorMessage, messages.MsgErrorGemLockNotFound) ||
strings.Contains(errorMessage, messages.MsgErrorNotFoundRequirementsTxt) {
logger.LogWarnWithLevel(strings.ReplaceAll(errorMessage, ";", ""))
return
}

logger.LogStringAsError(strings.ReplaceAll(errorMessage, ";", ""))
func (pr *PrintResults) printErrors(err string) {
logger.LogStringAsError(strings.ReplaceAll(err, ";", ""))
}
matheusalcantarazup marked this conversation as resolved.
Show resolved Hide resolved

func (pr *PrintResults) printResponseAnalysis() {
Expand Down