@@ -196,8 +196,13 @@ defaultJournalSafely = defaultJournalSafelyWith definputopts
196
196
-- | Read the default journal file specified by the environment,
197
197
-- with the given input options, or return an error message.
198
198
defaultJournalSafelyWith :: InputOpts -> IO (Either String Journal )
199
- defaultJournalSafelyWith iopts = defaultJournalPath >>= runExceptT . readJournalFile iopts
200
-
199
+ defaultJournalSafelyWith iopts = (do
200
+ f <- defaultJournalPath
201
+ runExceptT $ readJournalFile iopts f
202
+ ) `C.catches` [ -- XXX
203
+ C. Handler (\ (e :: C. ErrorCall ) -> return $ Left $ rstrip $ show e)
204
+ ,C. Handler (\ (e :: C. IOException ) -> return $ Left $ rstrip $ show e)
205
+ ]
201
206
-- | Get the default journal file path specified by the environment.
202
207
-- Like ledger, we look first for the LEDGER_FILE environment
203
208
-- variable, and if that does not exist, for the legacy LEDGER
@@ -256,6 +261,8 @@ readJournal iopts@InputOpts{strict_, _defer} mpath hdl = do
256
261
257
262
-- | Read a Journal from this file, or from stdin if the file path is -,
258
263
-- with strict checks if enabled, or return an error message.
264
+ -- XXX or, calls error if the file does not exist.
265
+ --
259
266
-- (Note strict checks are disabled temporarily here when this is called by readJournalFiles).
260
267
-- The file path can have a READER: prefix.
261
268
--
@@ -364,7 +371,7 @@ readJournalFiles' = orDieTrying . readJournalFiles definputopts
364
371
orDieTrying :: MonadIO m => ExceptT String m a -> m a
365
372
orDieTrying a = either (liftIO . fail ) return =<< runExceptT a
366
373
367
- -- | If the specified journal file does not exist (and is not "-"), give a helpful error and quit .
374
+ -- | If the specified journal file does not exist (and is not "-"), call error with an informative message .
368
375
-- (Using "journal file" generically here; it could be in any of hledger's supported formats.)
369
376
requireJournalFileExists :: FilePath -> IO ()
370
377
requireJournalFileExists " -" = return ()
0 commit comments