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

fix: logWithExit_ should exit on Just #278

Merged
merged 5 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Spectrometer Changelog

## Unreleased

- Fixes an issue where some `fossa` commands (including `fossa test`) would exit non-zero on success ([#278](https://github.com/fossas/spectrometer/pull/278)).

## v2.10.1

- Fixes an issue where `fossa container analyze` returned 0 exit code on failure ([#275](https://github.com/fossas/spectrometer/pull/275))
Expand Down
4 changes: 2 additions & 2 deletions src/Control/Carrier/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Control.Monad.Trans
import Data.Monoid (Endo (..))
import Data.Text (Text)
import Effect.Logger
import System.Exit (exitFailure)
import System.Exit (exitFailure, exitSuccess)

newtype DiagnosticsC m a = DiagnosticsC {runDiagnosticsC :: ReaderC [Text] (ErrorC SomeDiagnostic (WriterC (Endo [SomeDiagnostic]) m)) a}
deriving (Functor, Applicative, Monad, MonadIO)
Expand All @@ -52,7 +52,7 @@ logDiagnostic diag = do
-- | Exits with non-zero if the result is a failure.
-- | Useful for setting up diagnostics from CLI entry points.
elldritch marked this conversation as resolved.
Show resolved Hide resolved
logWithExit_ :: (Has (Lift IO) sig m, Has Logger sig m) => DiagnosticsC m () -> m ()
logWithExit_ diag = logDiagnostic diag >>= maybe (sendIO exitFailure) pure
logWithExit_ diag = logDiagnostic diag >>= maybe (sendIO exitFailure) (const (sendIO exitSuccess))

runDiagnostics :: Applicative m => DiagnosticsC m a -> m (Either FailureBundle a)
runDiagnostics = fmap bundle . runWriter (\w a -> pure (appEndo w [], a)) . runError @SomeDiagnostic . runReader [] . runDiagnosticsC
Expand Down