From c69b16d826c9c12e58de81cadee0218bf592ab5a Mon Sep 17 00:00:00 2001 From: Joseph Weston Date: Tue, 24 Jul 2018 19:41:50 +0200 Subject: [PATCH] lib: prefer use of 'parseErrorAt' to generic 'fail' 'fail' will just terminate the current parse branch, whereas here we have encountered a definite error. Also bring the code to get the current working directory inside 'getFilePaths', as it logically belongs there. --- hledger-lib/Hledger/Read/JournalReader.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 30969f4f7..335145da9 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -194,26 +194,25 @@ includedirectivep = do parentpos <- getPosition - curdir <- lift $ expandPath (takeDirectory $ sourceName parentpos) "" - `orRethrowIOError` (show parentpos ++ " locating " ++ filename) - - filepaths <- getFilePaths curdir filename + filepaths <- getFilePaths parentpos filename forM_ filepaths $ parseChild parentpos void newline where - getFilePaths curdir filename = do + getFilePaths parserpos filename = do + curdir <- lift $ expandPath (takeDirectory $ sourceName parserpos) "" + `orRethrowIOError` (show parserpos ++ " locating " ++ filename) -- Compiling filename as a glob pattern works even if it is a literal fileglob <- case tryCompileWith compDefault{errorRecovery=False} filename of Right x -> pure x - Left e -> fail $ "Invalid glob pattern: " ++ e + Left e -> parseErrorAt parserpos $ "Invalid glob pattern: " ++ e -- Get all matching files in the current working directory filepaths <- liftIO $ globDir1 fileglob curdir if (not . null) filepaths then pure filepaths - else fail $ "No existing files match pattern: " ++ filename + else parseErrorAt parserpos$ "No existing files match pattern: " ++ filename parseChild parentpos filepath = do childInput <- lift $ readFilePortably filepath