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

Conversation

elldritch
Copy link
Member

@elldritch elldritch commented Jul 6, 2021

Overview

Fixes a bug surfaced by d4f6bef. See the unexpected test failure at https://github.com/fossas/spectrometer/pull/277/checks?check_run_id=3000639861.

Previously, programs that ran a successful DiagnosticsC action under logWithExit_ would (incorrectly) continue evaluation. These are not the intended semantics. Instead, a successful run should exit successfully, much like how an unsuccessful run exits with failure.

This bug affects commands with steps after logWithExit_ e.g. fossa test always exits non-zero even on success.

Acceptance criteria

Actions run with logWithExit_ should exit zero on success.

Testing plan

Run a fossa test on a revision with no issues (I'm using the latest Spectrometer revision). See that it succeeds. Check that the exit code is zero.

cabal run fossa -- test --project https://github.com/fossas/spectrometer --revision 4f69104e2dcdb557a870c6621639750605261ca4 && echo OK

Risks

This significantly changes the semantics of logWithExit_. I believe these were the original intended semantics given that this is only ever used as a wrapper for commands (see grep logWithExit_), but other code that uses this will now abort surprisingly.

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.

@elldritch elldritch requested review from cnr and skilly-lily July 6, 2021 18:19
@elldritch
Copy link
Member Author

@cnr what's a good way to test this?

Is there a convenient way to do a single file with a small testMain, where I can check that the program fails to reach a line that causes it to exit non-zero?

@elldritch elldritch mentioned this pull request Jul 6, 2021
3 tasks
@cnr
Copy link
Contributor

cnr commented Jul 6, 2021

@liftM because exitSuccess/exitFailure really just throw IO Exceptions (throwIO ExitSuccess), you can test it with the hspec builtin shouldThrow:

  describe "foo" $ do
    it "should do the thing" $ do
      myAction `shouldThrow` (== ExitSuccess)

Copy link
Contributor

@cnr cnr left a comment

Choose a reason for hiding this comment

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

LGTM - did a cursory skim of all of the places we use logWithExit_ and didn't notice anything problematic. we only ever use it for program entrypoints

src/Control/Carrier/Diagnostics.hs Outdated Show resolved Hide resolved
@elldritch
Copy link
Member Author

Given that tests passed for 6dd5045, and that the integration test failure is due to a bad release (we should really build the integration test CLI from source, and have a separate test for the installer), I'm going to force-merge this into the mainline to get the release out.

@elldritch elldritch merged commit b420db6 into master Jul 6, 2021
@elldritch elldritch deleted the fix/logWithExit-should-exit-on-success branch July 6, 2021 19:33
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