imp: avoid ugly GHC 9.10.1 stack trace with nonexistent --conf file

This commit is contained in:
Simon Michael 2024-10-12 11:59:23 -10:00
parent 2db4b8ed56
commit 21e27a0283
2 changed files with 6 additions and 2 deletions

View File

@ -12,7 +12,7 @@ module Hledger.Cli.Conf (
)
where
import Control.Monad (void, forM)
import Control.Monad (void, forM, when)
import Control.Monad.Identity (Identity)
import Data.Functor ((<&>))
import qualified Data.Map as M
@ -110,6 +110,10 @@ getConf rawopts = do
-- | Read this config file and parse its contents, or raise an error.
readConfFile :: FilePath -> IO (Conf, Maybe FilePath)
readConfFile f = do
-- avoid GHC 9.10.1's ugly stack trace when calling readFile on a nonexistent file
exists <- doesFileExist f
when (not exists) $ error' $ f <> " does not exist"
ecs <- readFile f <&> parseConf f . T.pack
case ecs of
Left err -> error' $ errorBundlePretty err -- customErrorBundlePretty err

View File

@ -146,5 +146,5 @@ $ hledger -f /dev/null --conf nosuchfile --no-conf check
# ** 23. The rightmost --conf/--no-conf option wins, 2.
$ hledger -f /dev/null --no-conf --conf nosuchfile check
>2 /nosuchfile.*No such file/
>2 /nosuchfile does not exist/
>=1