diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-10-26 14:46:53 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-10-26 14:46:53 -0700 |
commit | 3d93414e5d433cad21ae2cbf45658d5789571f57 (patch) | |
tree | 08bdb5b0d08d1ab5871c3642f694f51971d96a91 /src/Text/Pandoc/Citeproc.hs | |
parent | dd3d920ba096b3415e11ea0a26d1f5efa4b18cc9 (diff) | |
download | pandoc-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.
Diffstat (limited to 'src/Text/Pandoc/Citeproc.hs')
-rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 12 |
1 files changed, 7 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 |