aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-10-26 14:46:53 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-10-26 14:46:53 -0700
commit3d93414e5d433cad21ae2cbf45658d5789571f57 (patch)
tree08bdb5b0d08d1ab5871c3642f694f51971d96a91
parentdd3d920ba096b3415e11ea0a26d1f5efa4b18cc9 (diff)
downloadpandoc-3d93414e5d433cad21ae2cbf45658d5789571f57.tar.gz
Add PandocBibliographyError and use it in parsing bibliographies.
This ensures that bibliography parsing errors generate messages that include the bibliography file name -- otherwise it can be quite mysterious where it is coming from. [API change] New PandocBibliographyError constructor on PandocError type.
-rw-r--r--src/Text/Pandoc/Citeproc.hs12
-rw-r--r--src/Text/Pandoc/Error.hs3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index ec7954d47..175fbadb2 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -28,7 +28,7 @@ import Text.Pandoc.Builder as B
import Text.Pandoc (PandocMonad(..), PandocError(..),
readDataFile, ReaderOptions(..), pandocExtensions,
report, LogMessage(..), fetchItem)
-import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines)
+import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines, tshow)
import qualified Text.Pandoc.UTF8 as UTF8
import Data.Aeson (eitherDecode)
import Data.Default
@@ -206,16 +206,18 @@ getRefs :: PandocMonad m
-> Maybe FilePath
-> ByteString
-> m [Reference Inlines]
-getRefs locale format idpred mbfp raw =
+getRefs locale format idpred mbfp raw = do
+ let err' = throwError .
+ PandocBibliographyError (maybe mempty T.pack mbfp)
case format of
Format_bibtex ->
- either (throwError . PandocAppError . T.pack . show) return .
+ either (err' . tshow) return .
readBibtexString Bibtex locale idpred . UTF8.toText $ raw
Format_biblatex ->
- either (throwError . PandocAppError . T.pack . show) return .
+ either (err' . tshow) return .
readBibtexString Biblatex locale idpred . UTF8.toText $ raw
Format_json ->
- either (throwError . PandocAppError . T.pack)
+ either (err' . T.pack)
(return . filter (idpred . unItemId . referenceId)) .
cslJsonToReferences $ raw
Format_yaml -> do
diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs
index bd24fec6f..93028ccca 100644
--- a/src/Text/Pandoc/Error.hs
+++ b/src/Text/Pandoc/Error.hs
@@ -62,6 +62,7 @@ data PandocError = PandocIOError Text IOError
| PandocUnknownWriterError Text
| PandocUnsupportedExtensionError Text Text
| PandocCiteprocError CiteprocError
+ | PandocBibliographyError Text Text
deriving (Show, Typeable, Generic)
instance Exception PandocError
@@ -143,6 +144,8 @@ handleError (Left e) =
"for " <> f
PandocCiteprocError e' -> err 24 $
prettyCiteprocError e'
+ PandocBibliographyError fp msg -> err 25 $
+ "Error reading bibliography file " <> fp <> ":\n" <> msg
err :: Int -> Text -> IO a
err exitCode msg = do