Skip to content

Commit

Permalink
error messages change
Browse files Browse the repository at this point in the history
  • Loading branch information
orto17 committed Dec 11, 2024
1 parent 48d1dbe commit 02faa20
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packagehandlers/conanpackagehandler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package packagehandlers

import (
"errors"
"fmt"
"github.com/jfrog/frogbot/v2/utils"
"github.com/jfrog/jfrog-client-go/utils/log"
Expand Down Expand Up @@ -47,23 +46,25 @@ func (conan *ConanPackageHandler) updateDirectDependency(vulnDetails *utils.Vuln
}
if !isAnyDescriptorFileChanged {
err = fmt.Errorf("impacted package '%s' was not found or could not be fixed in all descriptor files", vulnDetails.ImpactedDependencyName)
} else {
conan.logNoInstallationMessage()
}
conan.logNoInstallationMessage()
return
}

func (conan *ConanPackageHandler) updateConanFile(conanFile string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) {
data, err := os.ReadFile(conanFile)
if err != nil {
return false, errors.New("an error occurred while attempting to read the requirements file:\n" + err.Error())
return false, fmt.Errorf("an error occurred while attempting to read the requirements file '%s': %s\n", conanFile, err.Error())
}
currentFile := string(data)
fixedPackage := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.SuggestedFixedVersion
impactedDependency := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.ImpactedDependencyVersion
fixedFile := strings.Replace(currentFile, impactedDependency, strings.ToLower(fixedPackage), 1)

if fixedFile == currentFile {
return false, fmt.Errorf("impacted dependency '%s' not found in descriptor '%s', fix failed vulnerability", impactedDependency, conanFile)
log.Info(fmt.Sprintf("impacted dependency '%s' not found in descriptor '%s', moving to the next descriptor if exists...", impactedDependency, conanFile))
return false, nil
}
if err = os.WriteFile(conanFile, []byte(fixedFile), 0600); err != nil {
err = fmt.Errorf("an error occured while writing the fixed version of %s to the requirements file '%s': %s", conanFile, vulnDetails.ImpactedDependencyName, err.Error())
Expand Down

0 comments on commit 02faa20

Please sign in to comment.