Skip to content

Commit

Permalink
formatters/ruby:chore - removing unnecessary error messages (#1024)
Browse files Browse the repository at this point in the history
Previously if the project had ruby between programming languages but is
not a ruby on rails project or does not have a Gemfile.lock an error
would be reported for each scenario.

This pull request changes these error messages introduced in commits
cd839ef and 9245d7d to be considered just warnings, as there is no
need to point them out as errors, since it is only intended to
inform the user.

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
(cherry picked from commit 358fd4a)
  • Loading branch information
nathanmartinszup authored and matheusalcantarazup committed Mar 10, 2022
1 parent 0bd4d4d commit 649b267
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion internal/controllers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,12 @@ func (a *Analyzer) removeWarningsFromErrors() {
}

// isWarning workaround to check if the message it's form a warning until the formatters are refactored
// nolint:gocyclo // necessary complexity, but will be removed in the future
func (a *Analyzer) isWarning(err string) bool {
return strings.Contains(err, messages.MsgErrorPackageLockJSONNotFound) ||
strings.Contains(err, messages.MsgErrorYarnLockNotFound) ||
strings.Contains(err, messages.MsgErrorNotFoundRequirementsTxt) ||
strings.Contains(err, messages.MsgWarnPathIsInvalidGitRepository)
strings.Contains(err, messages.MsgWarnPathIsInvalidGitRepository) ||
strings.Contains(err, messages.MsgWarnBrakemanNotRubyOnRailsProject) ||
strings.Contains(err, messages.MsgWarnGemfileIsRequiredForBundler)
}
4 changes: 3 additions & 1 deletion internal/helpers/messages/warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ const (
// TODO: Remove MsgWarnAnalysisContainsOutdatedHash before release v2.10.0
MsgWarnAnalysisContainsOutdatedHash = "{HORUSEC_CLI} YOUR CONFIGURATION FILE CONTAINS SOME HASHES THAT WILL NO " +
"LONGER BE VALID AS OF v2.10.0 IS RELEASED. PLEASE UPDATE YOUR CONFIGURATION FILE WITH THE FOLLOWING HASHES:"
MsgWarnPathIsInvalidGitRepository = "{HORUSEC_CLI} The current path it's not a valid git repository"
MsgWarnPathIsInvalidGitRepository = "{HORUSEC_CLI} The current path it's not a valid git repository"
MsgWarnBrakemanNotRubyOnRailsProject = "brakeman only works on Ruby On Rails project"
MsgWarnGemfileIsRequiredForBundler = "Gemfile.lock file is required to execute Bundler analysis"
)
2 changes: 1 addition & 1 deletion internal/services/formatters/ruby/brakeman/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
notFoundError = "please supply the path to a rails application"
)

var ErrNotFoundRailsProject = errors.New("brakeman only works on Ruby On Rails project")
var ErrNotFoundRailsProject = errors.New(messages.MsgWarnBrakemanNotRubyOnRailsProject)

type Formatter struct {
formatters.IService
Expand Down
2 changes: 1 addition & 1 deletion internal/services/formatters/ruby/bundler/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
// nolint: stylecheck
// We actually want that this error message be capitalized since the file name that was
// not found is capitalized.
var ErrGemLockNotFound = errors.New("Gemfile.lock file is required to execute Bundler analysis")
var ErrGemLockNotFound = errors.New(messages.MsgWarnGemfileIsRequiredForBundler)

type Formatter struct {
formatters.IService
Expand Down

0 comments on commit 649b267

Please sign in to comment.