on master help sign in
Drop AppError
ef0786eSridhar Ratnakumar
lib/command/src/Obelisk/Command/CLI.hs+6−10
@@ -1,7 +1,7 @@
1{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE LambdaCase #-}
2module Obelisk.Command.CLI where
2module Obelisk.Command.CLI where
3
3
4−import Control.Exception (Exception, catch, handle, throw)
4+import Control.Exception (Exception, SomeException, catch, displayException, handle, throw)
5import Data.Text (Text)
5import Data.Text (Text)
6import qualified Data.Text as T
6import qualified Data.Text as T
7import qualified Data.Text.IO as T
7import qualified Data.Text.IO as T
@@ -11,13 +11,10 @@ import System.Exit (ExitCode (ExitFailure), exitWith)
11import System.Console.ANSI
11import System.Console.ANSI
12import System.Console.Questioner (dots1Spinner, stopIndicator)
12import System.Console.Questioner (dots1Spinner, stopIndicator)
13
13
14−newtype AppError = AppError Text
14+-- TODO: This doesn't handle the put* line of functions below, in that: when we print anything while the
15− deriving (Show, Typeable)
15+-- spinner is already running, it won't appear correctly in the terminal. The exception is `failWith` which
16−
16+-- raises an exception (that gets handled properly here). One solution to fix this problem is to run a
17−instance Exception AppError
17+-- singleton spinner thread and interact with it in order to print something.
18−
19−-- TODO: When printing warnings and such, the spinner should let them be printed
20−-- in new line (above the spinner)
21withSpinner
18withSpinner
22 :: String -- ^ Text to print alongside the spinner
19 :: String -- ^ Text to print alongside the spinner
23 -> Maybe String -- ^ Optional text to print at the end
20 -> Maybe String -- ^ Optional text to print at the end
@@ -29,8 +26,7 @@ withSpinner s e f = do
29 -- Upon exception (typically raised by failWith), stop the spinner, log the error and exit.
26 -- Upon exception (typically raised by failWith), stop the spinner, log the error and exit.
30 result <- catch f $ \exc -> do
27 result <- catch f $ \exc -> do
31 stopIndicator spinner
28 stopIndicator spinner
32− case exc of
29+ putError $ T.pack $ displayException (exc :: SomeException)
33− AppError err -> putError err
34 exitWith $ ExitFailure 2
30 exitWith $ ExitFailure 2
35
31
36 -- Upon no exceptions, stop the spinner and log the optional exit message.
32 -- Upon no exceptions, stop the spinner and log the optional exit message.