From 06cd0f947248e21b31756aa4925af7611aaf9aad Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 25 Apr 2025 08:29:40 -1000 Subject: [PATCH] lib: exitOnExceptions -> exitOnError --- hledger-lib/Hledger/Utils/IO.hs | 12 ++++++------ hledger-ui/Hledger/UI/Main.hs | 2 +- hledger-web/Hledger/Web/Main.hs | 2 +- hledger/Hledger/Cli.hs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index 173124e88..763d10127 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -24,9 +24,9 @@ module Hledger.Utils.IO ( warn, ansiFormatError, ansiFormatWarning, - exitOnExceptions, - exitWithError, printError, + exitWithErrorMessage, + exitOnError, -- * Time getCurrentLocalTime, @@ -247,8 +247,6 @@ modifyFirstLine f s = intercalate "\n" $ map f l <> ls where (l,ls) = splitAt 1 -- ExitCode (triggered by a call to exitSuccess, exitFailure, or exitWith) -- and UserInterrupt (triggered by control-C). -- -exitOnExceptions :: IO () -> IO () -exitOnExceptions = flip catches [Handler (\(e::ErrorCall) -> exitWithError $ rstrip $ show e) ,Handler (\(e::IOError) -> exitWithError $ rstrip $ show e) -- ,Handler (\(x::ExitCode) -> exitWith x) -- falls through @@ -259,8 +257,6 @@ exitOnExceptions = flip catches -- | Print an error message with printError, -- then exit the program with a non-zero exit code. -exitWithError :: String -> IO () -exitWithError msg = printError msg >> exitFailure -- | Print an error message to stderr, -- with a standard program name prefix, @@ -278,6 +274,10 @@ printError msg = do <> (if "Error:" `isPrefixOf` msg then "" else "Error: ") hPutStrLn stderr $ style $ prefix <> msg +exitWithErrorMessage :: String -> IO () +exitWithErrorMessage msg = printError msg >> exitFailure +exitOnError :: IO () -> IO () +exitOnError = flip catches -- Time getCurrentLocalTime :: IO LocalTime diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index c7b803b64..91b2307a7 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -76,7 +76,7 @@ writeChan = BC.writeBChan hledgerUiMain :: IO () -hledgerUiMain = exitOnExceptions $ withGhcDebug' $ withProgName "hledger-ui.log" $ do -- force Hledger.Utils.Debug.* to log to hledger-ui.log +hledgerUiMain = exitOnError $ withGhcDebug' $ withProgName "hledger-ui.log" $ do -- force Hledger.Utils.Debug.* to log to hledger-ui.log when (ghcDebugMode == GDPauseAtStart) $ ghcDebugPause' #if MIN_VERSION_base(4,20,0) diff --git a/hledger-web/Hledger/Web/Main.hs b/hledger-web/Hledger/Web/Main.hs index 6db8b3667..2eb4b1705 100644 --- a/hledger-web/Hledger/Web/Main.hs +++ b/hledger-web/Hledger/Web/Main.hs @@ -61,7 +61,7 @@ hledgerWebDev = -- Run normally. hledgerWebMain :: IO () -hledgerWebMain = exitOnExceptions $ withGhcDebug' $ do +hledgerWebMain = exitOnError $ withGhcDebug' $ do when (ghcDebugMode == GDPauseAtStart) $ ghcDebugPause' #if MIN_VERSION_base(4,20,0) diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 78ee4a07f..dae5f9ca8 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -200,7 +200,7 @@ confflagsmode = defMode{ -- implementing that would simplify hledger's CLI processing a lot. -- main :: IO () -main = exitOnExceptions $ withGhcDebug' $ do +main = exitOnError $ withGhcDebug' $ do #if MIN_VERSION_base(4,20,0) -- Control ghc 9.10+'s stack traces.