From b6a1cf5eb71cb887cf186bbe7f2f7ec57ca3f14b Mon Sep 17 00:00:00 2001 From: Nathan Martins Date: Thu, 10 Mar 2022 10:58:59 -0300 Subject: [PATCH] formatters/ruby:chore - removing unnecessary error messages 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 --- internal/controllers/analyzer/analyzer.go | 5 ++++- internal/helpers/messages/warn.go | 4 +++- internal/services/formatters/ruby/brakeman/formatter.go | 2 +- internal/services/formatters/ruby/bundler/formatter.go | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/controllers/analyzer/analyzer.go b/internal/controllers/analyzer/analyzer.go index f1998134f..c325370bc 100644 --- a/internal/controllers/analyzer/analyzer.go +++ b/internal/controllers/analyzer/analyzer.go @@ -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) } diff --git a/internal/helpers/messages/warn.go b/internal/helpers/messages/warn.go index 4d7ed341b..7689c0dba 100644 --- a/internal/helpers/messages/warn.go +++ b/internal/helpers/messages/warn.go @@ -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" ) diff --git a/internal/services/formatters/ruby/brakeman/formatter.go b/internal/services/formatters/ruby/brakeman/formatter.go index af1cf31fd..3ad389f0d 100644 --- a/internal/services/formatters/ruby/brakeman/formatter.go +++ b/internal/services/formatters/ruby/brakeman/formatter.go @@ -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 diff --git a/internal/services/formatters/ruby/bundler/formatter.go b/internal/services/formatters/ruby/bundler/formatter.go index 55d56fab2..29f921f3d 100644 --- a/internal/services/formatters/ruby/bundler/formatter.go +++ b/internal/services/formatters/ruby/bundler/formatter.go @@ -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