diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-08-15 17:21:56 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-08-15 17:21:56 -0700 |
commit | 172f020bc5b59950afd29411b7d80200d0b38e83 (patch) | |
tree | 6c03f7c762130ac3ecad09c971ad69f3139d32a7 | |
parent | 5af0de23cc60ab02b351e075992f6a936acdf19e (diff) | |
download | pandoc-172f020bc5b59950afd29411b7d80200d0b38e83.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index d670a35bc..72b467da5 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -583,8 +583,7 @@ readDefaultDataFile :: FilePath -> IO BS.ByteString readDefaultDataFile fname = #ifdef EMBED_DATA_FILES case lookup (makeCanonical fname) dataFiles of - Nothing -> ioError $ userError - $ "Data file `" ++ fname ++ "' does not exist" + Nothing -> err 97 $ "Could not find data file " ++ fname Just contents -> return contents where makeCanonical = joinPath . transformPathParts . splitDirectories transformPathParts = reverse . foldl go [] @@ -592,7 +591,12 @@ readDefaultDataFile fname = go (_:as) ".." = as go as x = x : as #else - getDataFileName ("data" </> fname) >>= BS.readFile + getDataFileName ("data" </> fname) >>= checkExistence >>= BS.readFile + where checkExistence fn = do + exists <- doesFileExist fn + if exists + then return fn + else err 97 ("Could not find data file " ++ fname) #endif -- | Read file from specified user data directory or, if not found there, from |