imp:include: better errors, eg for missing argument; more debug output

This commit is contained in:
Simon Michael 2025-07-11 12:13:52 -07:00
parent c8a5b8eb37
commit 801a7adaa4

View File

@ -299,6 +299,8 @@ includedirectivep = do
lift followingcommentp lift followingcommentp
-- find file(s) -- find file(s)
let (mprefix,glb) = splitReaderPrefix prefixedglob let (mprefix,glb) = splitReaderPrefix prefixedglob
when (null $ dbg7 "glob pattern" glb) $
customFailure $ parseErrorAt off $ "include needs a file path or glob pattern argument"
paths <- getFilePaths off pos glb paths <- getFilePaths off pos glb
let prefixedpaths = case mprefix of let prefixedpaths = case mprefix of
Nothing -> paths Nothing -> paths
@ -323,12 +325,11 @@ includedirectivep = do
let parentfilepath = sourceName parserpos let parentfilepath = sourceName parserpos
realparentfilepath <- liftIO $ canonicalizePath parentfilepath -- Follow a symlink. If the path is already absolute, the operation never fails. realparentfilepath <- liftIO $ canonicalizePath parentfilepath -- Follow a symlink. If the path is already absolute, the operation never fails.
let curdir = takeDirectory realparentfilepath let curdir = takeDirectory realparentfilepath
-- Find all matched files, in lexicographic order mimicking the output of 'ls'. -- Find all matched files, in lexicographic order (the order ls would normally show them)
filepaths <- liftIO $ sort <$> globDir1 fileglob curdir filepaths <- liftIO $ (dbg7 "include: matched files" . sort) <$> globDir1 fileglob curdir
if (not . null) filepaths if (not . null) filepaths
then pure filepaths then pure filepaths
else customFailure $ parseErrorAt parseroff $ else customFailure $ parseErrorAt parseroff $ "No files were matched by file pattern: " ++ fileglobpattern
"No existing files match pattern: " ++ fileglobpattern
-- Parse the given included file (and any deeper includes, recursively) -- Parse the given included file (and any deeper includes, recursively)
-- as if it was inlined in the current (parent) file. -- as if it was inlined in the current (parent) file.