git.iko.soy/typeable/pandoc
on master help sign in
Shared: Better error message when default data file not found.

Listing the full path can confuse people who are using `--self-contained`: they might have intended the file to be found locally. So now we just list the data file name.

commit172f020bc5b59950afd29411b7d80200d0b38e83 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 15 Aug 2013, 17:21 (13 years ago) parent5af0de2
1 file changed+7−3
src/Text/Pandoc/Shared.hs+7−3
src/Text/Pandoc/Shared.hs+7−3
@@ -583,8 +583,7 @@ readDefaultDataFile :: FilePath -> IO BS.ByteString
583583readDefaultDataFile fname =
584584#ifdef EMBED_DATA_FILES
585585 case lookup (makeCanonical fname) dataFiles of
586− Nothing -> ioError $ userError
587− $ "Data file `" ++ fname ++ "' does not exist"
586+ Nothing -> err 97 $ "Could not find data file " ++ fname
588587 Just contents -> return contents
589588 where makeCanonical = joinPath . transformPathParts . splitDirectories
590589 transformPathParts = reverse . foldl go []
@@ -592,7 +591,12 @@ readDefaultDataFile fname =
592591 go (_:as) ".." = as
593592 go as x = x : as
594593#else
595− getDataFileName ("data" </> fname) >>= BS.readFile
594+ getDataFileName ("data" </> fname) >>= checkExistence >>= BS.readFile
595+ where checkExistence fn = do
596+ exists <- doesFileExist fn
597+ if exists
598+ then return fn
599+ else err 97 ("Could not find data file " ++ fname)
596600#endif
597601
598602-- | Read file from specified user data directory or, if not found there, from