on master help sign in
withSpinner should respect single-responsibility-principle

Don't have it do printing of errors. Just clean up on final.

commit2835ba07fc931fa4ae73c7f7e1f9d3b95c8e4dde authorSridhar Ratnakumar <srid@srid.ca> dateThu 10 May 2018, 10:53 (8 years ago) parentef0786e
2 files changed+2−13
lib/command/src/Obelisk/Command.hs−1 lib/command/src/Obelisk/Command/CLI.hs+2−12
lib/command/src/Obelisk/Command.hs−1
@@ -174,7 +174,6 @@ main = do
174174 Args noHandoffPassed cmd <- handleParseResult (execParserPure parserPrefs argsInfo as)
175175 case noHandoffPassed of
176176 False -> return ()
177− --TODO: Use a proper logging system with log levels and whatnot
178177 True -> putWarning "--no-handoff should only be passed once and as the first argument; ignoring"
179178 ob cmd
180179 handoffAndGo as = findProjectObeliskCommand "." >>= \case
lib/command/src/Obelisk/Command/CLI.hs+2−12
@@ -1,11 +1,10 @@
11{-# LANGUAGE LambdaCase #-}
22module Obelisk.Command.CLI where
33
4−import Control.Exception (Exception, SomeException, catch, displayException, handle, throw)
4+import Control.Exception (SomeException, displayException, finally, handle)
55import Data.Text (Text)
66import qualified Data.Text as T
77import qualified Data.Text.IO as T
8−import Data.Typeable (Typeable)
98import System.Exit (ExitCode (ExitFailure), exitWith)
109
1110import System.Console.ANSI
@@ -22,15 +21,8 @@ withSpinner
2221 -> IO a
2322withSpinner s e f = do
2423 spinner <- dots1Spinner (1000 * 200) s
25−
26− -- Upon exception (typically raised by failWith), stop the spinner, log the error and exit.
27− result <- catch f $ \exc -> do
24+ result <- finally f $ do
2825 stopIndicator spinner
29− putError $ T.pack $ displayException (exc :: SomeException)
30− exitWith $ ExitFailure 2
31−
32− -- Upon no exceptions, stop the spinner and log the optional exit message.
33− stopIndicator spinner
3426 case e of
3527 Just exitMsg -> putInfo $ T.pack exitMsg
3628 _ -> return ()
@@ -38,8 +30,6 @@ withSpinner s e f = do
3830
3931data Level = Level_Normal | Level_Warning | Level_Error
4032
41−-- | Prefer this over the alternative ways to exit the program with an error message as it automatically
42−-- takes care of cleaning on spinners.
4333-- TODO: Handle this error cleanly when evaluating outside of `withSpinner` (eg: runCLI)
4434failWith :: Text -> IO a
4535failWith = ioError . userError . T.unpack