From 3d93414e5d433cad21ae2cbf45658d5789571f57 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 26 Oct 2020 14:46:53 -0700 Subject: 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. --- src/Text/Pandoc/Citeproc.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Citeproc.hs') 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 -- cgit v1.2.3