From b7c4dc3b5368522fe34d817fa9437bb193a594a7 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 11 Jul 2025 13:00:51 -0700 Subject: [PATCH] fix:journal: cyclic include error messages now show the correct line --- hledger-lib/Hledger/Read/JournalReader.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index ad231377c..7504b12af 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -306,7 +306,7 @@ includedirectivep = do Nothing -> paths Just fmt -> map ((show fmt++":")++) paths -- parse them inline - forM_ prefixedpaths $ parseIncludedFile pos + forM_ prefixedpaths $ parseIncludedFile off pos where @@ -334,19 +334,20 @@ includedirectivep = do -- Parse the given included file (and any deeper includes, recursively) -- as if it was inlined in the current (parent) file. -- The position in the parent file is provided for error messages. - parseIncludedFile :: MonadIO m => SourcePos -> PrefixedFilePath -> ErroringJournalParser m () - parseIncludedFile parentpos prefixedpath = do + parseIncludedFile :: MonadIO m => Int -> SourcePos -> PrefixedFilePath -> ErroringJournalParser m () + parseIncludedFile off pos prefixedpath = do let (_mprefix,filepath) = splitReaderPrefix prefixedpath + -- Throw an error if a cycle is detected parentj <- get let parentfilestack = jincludefilestack parentj when (filepath `elem` parentfilestack) $ - Fail.fail ("Cyclic include: " ++ filepath) + customFailure $ parseErrorAt off $ "Cyclic include: " ++ filepath childInput <- dbg6Msg ("parseChild: "++takeFileName filepath) $ lift $ readFilePortably filepath - `orRethrowIOError` (show parentpos ++ " reading " ++ filepath) + `orRethrowIOError` (show pos ++ " reading " ++ filepath) let initChildj = newJournalWithParseStateFrom filepath parentj -- Choose a reader/parser based on the file path prefix or file extension,