imp: avoid ugly GHC 9.10.1 stack trace with nonexistent --conf file
This commit is contained in:
parent
2db4b8ed56
commit
21e27a0283
@ -12,7 +12,7 @@ module Hledger.Cli.Conf (
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Control.Monad (void, forM)
|
import Control.Monad (void, forM, when)
|
||||||
import Control.Monad.Identity (Identity)
|
import Control.Monad.Identity (Identity)
|
||||||
import Data.Functor ((<&>))
|
import Data.Functor ((<&>))
|
||||||
import qualified Data.Map as M
|
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.
|
-- | Read this config file and parse its contents, or raise an error.
|
||||||
readConfFile :: FilePath -> IO (Conf, Maybe FilePath)
|
readConfFile :: FilePath -> IO (Conf, Maybe FilePath)
|
||||||
readConfFile f = do
|
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
|
ecs <- readFile f <&> parseConf f . T.pack
|
||||||
case ecs of
|
case ecs of
|
||||||
Left err -> error' $ errorBundlePretty err -- customErrorBundlePretty err
|
Left err -> error' $ errorBundlePretty err -- customErrorBundlePretty err
|
||||||
|
|||||||
@ -146,5 +146,5 @@ $ hledger -f /dev/null --conf nosuchfile --no-conf check
|
|||||||
|
|
||||||
# ** 23. The rightmost --conf/--no-conf option wins, 2.
|
# ** 23. The rightmost --conf/--no-conf option wins, 2.
|
||||||
$ hledger -f /dev/null --no-conf --conf nosuchfile check
|
$ hledger -f /dev/null --no-conf --conf nosuchfile check
|
||||||
>2 /nosuchfile.*No such file/
|
>2 /nosuchfile does not exist/
|
||||||
>=1
|
>=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user