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