Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Use Diag.logWithExit_ to prevent exiting 0 on failure. (#275)
Browse files Browse the repository at this point in the history
* Should non-zero when syft fails

* use logWithExit_ for report and test commands

* update changelog
  • Loading branch information
Wesley Van Melle authored Jul 2, 2021
1 parent 2649026 commit d4f6bef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 48 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Spectrometer Changelog

## v2.10.1

- Fixes an issue where `fossa container analyze` returned 0 exit code on failure ([#275](https://github.com/fossas/spectrometer/pull/275))

## v2.10.0

- Adds support for short flags to mirror CLI v1 commands ([#264](https://github.com/fossas/spectrometer/pull/264))
- Added a `remote-dependencies` section in the `fossa-deps` file to support archives at remote locations ([#260](https://github.com/fossas/spectrometer/pull/260))
- Modify the payload for `custom-dependencies` to include optional fields in a new `metadata` section ([#260](https://github.com/fossas/spectrometer/pull/260))

## v2.9.2

- Adds JSON-formatted project information to the output of `fossa analyze` with `--json` ([#255](https://github.com/fossas/spectrometer/pull/255))

## v2.9.1

- Bump wiggins - Updated vps aosp-notice-file subcommand to upload ninja files & trigger async task. ([#272](https://github.com/fossas/spectrometer/pull/272))

## v2.9.0
Expand Down
13 changes: 3 additions & 10 deletions src/App/Fossa/Container/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import App.Fossa.Analyze (ScanDestination (..))
import App.Fossa.Container (ImageText (..), extractRevision, runSyft, toContainerScan)
import App.Fossa.FossaAPIV1 (UploadResponse (uploadError, uploadLocator), uploadContainerScan)
import App.Types (OverrideProject (..), ProjectRevision (..))
import Control.Carrier.Diagnostics (
Diagnostics,
renderFailureBundle,
runDiagnostics,
)
import Control.Carrier.Diagnostics (Diagnostics, logWithExit_)
import Control.Effect.Lift (Lift)
import Control.Monad.IO.Class (MonadIO)
import Data.Aeson
import Data.Aeson (encode)
import Data.Foldable (traverse_)
import Data.Maybe (fromMaybe)
import Data.String.Conversion (decodeUtf8)
Expand All @@ -23,10 +19,7 @@ import Srclib.Types (parseLocator)

analyzeMain :: ScanDestination -> Severity -> OverrideProject -> ImageText -> IO ()
analyzeMain scanDestination logSeverity override image = withDefaultLogger logSeverity $ do
result <- runDiagnostics $ analyze scanDestination override image
case result of
Left err -> logError (renderFailureBundle err)
Right _ -> pure ()
logWithExit_ $ analyze scanDestination override image

analyze ::
( Has Diagnostics sig m
Expand Down
13 changes: 3 additions & 10 deletions src/App/Fossa/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import App.Fossa.ProjectInference
import App.Types
import Control.Carrier.Diagnostics
import Control.Carrier.StickyLogger (logSticky, runStickyLogger)
import Control.Effect.Lift (sendIO)
import Data.Aeson qualified as Aeson
import Data.Functor (void)
import Data.String.Conversion (decodeUtf8)
Expand All @@ -18,7 +17,7 @@ import Data.Text.IO (hPutStrLn)
import Effect.Logger
import Effect.ReadFS
import Fossa.API.Types (ApiOpts)
import System.Exit (exitFailure, exitSuccess)
import System.Exit (exitFailure)
import System.IO (stderr)

data ReportType
Expand Down Expand Up @@ -50,8 +49,8 @@ reportMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds reportType overr
* Timeout over `IO a` (easy to move, but where do we move it?)
* CLI command refactoring as laid out in https://github.com/fossas/issues/issues/129
-}
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $ do
result <- runDiagnostics . runReadFSIO $ do
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $
logWithExit_ . runReadFSIO $ do
revision <- mergeOverride override <$> (inferProjectFromVCS basedir <||> inferProjectCached basedir <||> inferProjectDefault basedir)

logInfo ""
Expand All @@ -74,11 +73,5 @@ reportMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds reportType overr

logStdout . decodeUtf8 $ Aeson.encode jsonValue

case result of
Left err -> do
logError $ renderFailureBundle err
sendIO exitFailure
Right _ -> sendIO exitSuccess

hPutStrLn stderr "Timed out while waiting for build/issues scan"
exitFailure
12 changes: 3 additions & 9 deletions src/App/Fossa/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Data.Text.IO (hPutStrLn)
import Effect.Logger
import Effect.ReadFS
import Fossa.API.Types (ApiOpts, Issues (..))
import System.Exit (exitFailure, exitSuccess)
import System.Exit (exitFailure)
import System.IO (stderr)

data TestOutputType
Expand All @@ -35,8 +35,8 @@ testMain ::
OverrideProject ->
IO ()
testMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds outputType override = do
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $ do
result <- runDiagnostics . runReadFSIO $ do
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $
logWithExit_ . runReadFSIO $ do
revision <- mergeOverride override <$> (inferProjectFromVCS basedir <||> inferProjectCached basedir <||> inferProjectDefault basedir)

logInfo ""
Expand Down Expand Up @@ -64,12 +64,6 @@ testMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds outputType overrid

sendIO exitFailure

case result of
Left failure -> do
logError $ renderFailureBundle failure
sendIO exitFailure
Right _ -> sendIO exitSuccess

-- we call exitSuccess/exitFailure in each branch above. the only way we get
-- here is if we time out
hPutStrLn stderr "Timed out while waiting for issues scan"
Expand Down
13 changes: 3 additions & 10 deletions src/App/Fossa/VPS/Report.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import App.Fossa.VPS.Scan.ScotlandYard qualified as ScotlandYard
import App.Types
import Control.Carrier.Diagnostics
import Control.Carrier.StickyLogger (logSticky, runStickyLogger)
import Control.Effect.Lift (sendIO)
import Data.Aeson qualified as Aeson
import Data.Functor (void)
import Data.String.Conversion (decodeUtf8)
Expand All @@ -20,7 +19,7 @@ import Data.Text.IO (hPutStrLn)
import Effect.Logger
import Effect.ReadFS
import Fossa.API.Types (ApiOpts)
import System.Exit (exitFailure, exitSuccess)
import System.Exit (exitFailure)
import System.IO (stderr)

data ReportType
Expand Down Expand Up @@ -52,8 +51,8 @@ reportMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds reportType overr
* Timeout over `IO a` (easy to move, but where do we move it?)
* CLI command refactoring as laid out in https://github.com/fossas/issues/issues/129
-}
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $ do
result <- runDiagnostics . runReadFSIO $ do
void . timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $
logWithExit_ . runReadFSIO $ do
revision <- mergeOverride override <$> (inferProjectFromVCS basedir <||> inferProjectCached basedir <||> inferProjectDefault basedir)

logSticky "[ Getting latest scan ID ]"
Expand All @@ -77,11 +76,5 @@ reportMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds reportType overr

logStdout . decodeUtf8 $ Aeson.encode jsonValue

case result of
Left err -> do
logError $ renderFailureBundle err
sendIO exitFailure
Right _ -> sendIO exitSuccess

hPutStrLn stderr "Timed out while waiting for build/issues scan"
exitFailure
12 changes: 3 additions & 9 deletions src/App/Fossa/VPS/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Data.Text.IO (hPutStrLn)
import Effect.Logger
import Effect.ReadFS
import Fossa.API.Types (ApiOpts, Issues (..))
import System.Exit (exitFailure, exitSuccess)
import System.Exit (exitFailure)
import System.IO (stderr)

data TestOutputType
Expand All @@ -37,8 +37,8 @@ testMain ::
OverrideProject ->
IO ()
testMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds outputType override = do
_ <- timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $ do
result <- runDiagnostics . runReadFSIO $ do
_ <- timeout timeoutSeconds . withDefaultLogger logSeverity . runStickyLogger SevInfo $
logWithExit_ . runReadFSIO $ do
revision <- mergeOverride override <$> (inferProjectFromVCS basedir <||> inferProjectCached basedir <||> inferProjectDefault basedir)

logInfo ""
Expand Down Expand Up @@ -71,12 +71,6 @@ testMain (BaseDir basedir) apiOpts logSeverity timeoutSeconds outputType overrid
TestOutputJson -> logStdout . decodeUtf8 . Aeson.encode $ issues
sendIO exitFailure

case result of
Left failure -> do
logError $ renderFailureBundle failure
sendIO exitFailure
Right _ -> sendIO exitSuccess

-- we call exitSuccess/exitFailure in each branch above. the only way we get
-- here is if we time out
hPutStrLn stderr "Timed out while waiting for issues scan"
Expand Down

0 comments on commit d4f6bef

Please sign in to comment.