diff --git a/hledger/Hledger/Cli/Conf.hs b/hledger/Hledger/Cli/Conf.hs index 4bc30e6a0..3648505c7 100644 --- a/hledger/Hledger/Cli/Conf.hs +++ b/hledger/Hledger/Cli/Conf.hs @@ -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 diff --git a/hledger/test/cli/cli.test b/hledger/test/cli/cli.test index cb5a70c43..30580db66 100644 --- a/hledger/test/cli/cli.test +++ b/hledger/test/cli/cli.test @@ -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