From 00f6a832d45ce7b690ca533be2accb6b3eaf77d7 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 1 Dec 2025 05:45:10 -0800 Subject: [PATCH] fix:journal: consistent error message when include has no argument --- hledger-lib/Hledger/Read/JournalReader.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 579bf92de..4a06a09c3 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -304,16 +304,21 @@ includedirectivep iopts = do -- save the position at start of include directive, for error messages eoff <- getOffset pos <- getSourcePos + let errorNoArg = customFailure $ parseErrorAt eoff "include needs a file path or glob pattern argument" -- parse the directive string "include" - lift skipNonNewlineSpaces1 - prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n']) - lift followingcommentp + -- notFollowedBy newline "a file path or glob pattern argument" + prefixedglob <- (do + lift skipNonNewlineSpaces1 + prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n']) + lift followingcommentp + return prefixedglob + ) <|> errorNoArg + let (mprefix,glb) = splitReaderPrefix prefixedglob parentf <- sourcePosFilePath pos -- a little slow, don't do too often - when (null $ dbg6 (parentf <> " include: glob pattern") glb) $ - customFailure $ parseErrorAt eoff $ "include needs a file path or glob pattern argument" + when (null $ dbg6 (parentf <> " include: glob pattern") glb) errorNoArg -- Find the file or glob-matched files (just the ones from this include directive), with some IO error checking. -- Also report whether a glob pattern was used, and not just a literal file path.