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

Use Diag.logWithExit_ to prevent exiting 0 on failure. #275

Merged
merged 3 commits into from
Jul 2, 2021

Conversation

skilly-lily
Copy link
Contributor

@skilly-lily skilly-lily commented Jul 1, 2021

Overview

During fossa container analyze, when syft fails, we exit with 0. This is because our raw diagnostic handler does not control exiting values. Using Diag.logWithExit_, we can safely handle errors which terminate the program, and automatically return non-zero exit codes.

This PR migrates all eligible entry points to using Diag.logWithExit_.

Acceptance criteria

  • Every entry point with the following pattern uses Diag.logWithExit_, instead of handling manually:
    • Returns IO ()
    • Reports error to stderr using default format/layout.
    • Diagnostic success/failure directly translates to program success/failure
    • A pre-existing logger is in use.

Testing plan

Test all modified commands in failure mode, confirm non-zero exit code.

References

Reported here http://fossa.zendesk.com/agent/tickets/2814
Closes fossas/team-analysis#626

Checklist

  • I added tests for this PR's change (or confirmed tests are not viable).
  • I linted and formatted (via haskell-language-server) any haskell files I touched in this PR.
  • If this PR introduced a user-visible change, I added documentation into docs/.
  • I updated Changelog.md if this change is externally facing. If this PR did not mark a release, I added my changes into an # Unreleased section at the top.
  • I linked this PR to any referenced GitHub issues, if they exist.

@skilly-lily skilly-lily requested a review from zlav July 1, 2021 20:38
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the culprit for why this PR was necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

Copy link
Member

@zlav zlav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, good refactor on the other parts

@skilly-lily skilly-lily merged commit d4f6bef into master Jul 2, 2021
@skilly-lily skilly-lily deleted the fix/syft-non-zero branch July 2, 2021 17:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants