From ee38cf826c0a24717a9d10c2035d35844f324099 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Thu, 15 Aug 2024 15:43:07 +0300 Subject: [PATCH] change log.Fatal to return err --- internal/commands/scan.go | 6 ++++-- .../services/osinstaller/linux-mac-utils.go | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index be5dcbe80..9cc112f97 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -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) diff --git a/internal/services/osinstaller/linux-mac-utils.go b/internal/services/osinstaller/linux-mac-utils.go index e68b930e9..95349517b 100644 --- a/internal/services/osinstaller/linux-mac-utils.go +++ b/internal/services/osinstaller/linux-mac-utils.go @@ -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 { @@ -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