Skip to content

Commit

Permalink
change log.Fatal to return err
Browse files Browse the repository at this point in the history
  • Loading branch information
tamarleviCm committed Aug 15, 2024
1 parent 86c3ddb commit ee38cf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2101,10 +2101,12 @@ func isScanRunning(
var err error
scanResponseModel, errorModel, err = scansWrapper.GetByID(scanID)
if err != nil {
log.Fatal("Cannot source code temp file.", err)
logger.PrintfIfVerbose("Cannot source code temp file: %s", err)
return false, errors.Wrap(err, "Cannot source code temp file.")
}
if errorModel != nil {
log.Fatalf(fmt.Sprintf("%s: CODE: %d, %s", failedGetting, errorModel.Code, errorModel.Message))
logger.PrintfIfVerbose("%s: CODE: %d, %s", failedGetting, errorModel.Code, errorModel.Message)
return false, errors.Errorf("%s: CODE: %d, %s", failedGetting, errorModel.Code, errorModel.Message)
} else if scanResponseModel != nil {
if scanResponseModel.Status == wrappers.ScanRunning || scanResponseModel.Status == wrappers.ScanQueued {
log.Println("Scan status: ", scanResponseModel.Status)
Expand Down
18 changes: 10 additions & 8 deletions internal/services/osinstaller/linux-mac-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ func extractFiles(installationConfiguration *InstallationConfiguration, tarReade
}

if err != nil {
log.Fatalf("ExtractTarGz: Next() failed: %s", err.Error())
logger.PrintfIfVerbose("ExtractTarGz: Next() failed: %s", err.Error())
return err
}

switch header.Typeflag {
case tar.TypeDir:
if err := os.Mkdir(header.Name, os.FileMode(dirDefault)); err != nil {
log.Fatalf("ExtractTarGz: Mkdir() failed: %s", err.Error())
logger.PrintfIfVerbose("ExtractTarGz: Mkdir() failed: %s", err.Error())
return err
}
case tar.TypeReg:
extractedFilePath := filepath.Join(installationConfiguration.WorkingDir(), header.Name)
outFile, err := os.Create(extractedFilePath)
if err != nil {
log.Fatalf("ExtractTarGz: Create() failed: %s", err.Error())
logger.PrintfIfVerbose("ExtractTarGz: Create() failed: %s", err.Error())
return err
}
if _, err = io.Copy(outFile, tarReader); err != nil {
log.Fatalf("ExtractTarGz: Copy() failed: %s", err.Error())
logger.PrintfIfVerbose("ExtractTarGz: Copy() failed: %s", err.Error())
return err
}
err = outFile.Close()
if err != nil {
Expand All @@ -78,10 +82,8 @@ func extractFiles(installationConfiguration *InstallationConfiguration, tarReade
return err
}
default:
log.Fatalf(
"ExtractTarGz: uknown type: %v in %s",
header.Typeflag,
header.Name)
logger.PrintfIfVerbose("ExtractTarGz: uknown type: %v in %s", header.Typeflag, header.Name)
return err
}
}
return nil
Expand Down

0 comments on commit ee38cf8

Please sign in to comment.