git.iko.soy/typeable/pandoc
on master help sign in
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.

commit3d93414e5d433cad21ae2cbf45658d5789571f57 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 26 Oct 2020, 14:46 (6 years ago) parentdd3d920
2 files changed+10−5
src/Text/Pandoc/Citeproc.hs+7−5 src/Text/Pandoc/Error.hs+3
src/Text/Pandoc/Citeproc.hs+7−5
@@ -28,7 +28,7 @@ import Text.Pandoc.Builder as B
2828import Text.Pandoc (PandocMonad(..), PandocError(..),
2929 readDataFile, ReaderOptions(..), pandocExtensions,
3030 report, LogMessage(..), fetchItem)
31−import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines)
31+import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines, tshow)
3232import qualified Text.Pandoc.UTF8 as UTF8
3333import Data.Aeson (eitherDecode)
3434import Data.Default
@@ -206,16 +206,18 @@ getRefs :: PandocMonad m
206206 -> Maybe FilePath
207207 -> ByteString
208208 -> m [Reference Inlines]
209−getRefs locale format idpred mbfp raw =
209+getRefs locale format idpred mbfp raw = do
210+ let err' = throwError .
211+ PandocBibliographyError (maybe mempty T.pack mbfp)
210212 case format of
211213 Format_bibtex ->
212− either (throwError . PandocAppError . T.pack . show) return .
214+ either (err' . tshow) return .
213215 readBibtexString Bibtex locale idpred . UTF8.toText $ raw
214216 Format_biblatex ->
215− either (throwError . PandocAppError . T.pack . show) return .
217+ either (err' . tshow) return .
216218 readBibtexString Biblatex locale idpred . UTF8.toText $ raw
217219 Format_json ->
218− either (throwError . PandocAppError . T.pack)
220+ either (err' . T.pack)
219221 (return . filter (idpred . unItemId . referenceId)) .
220222 cslJsonToReferences $ raw
221223 Format_yaml -> do
src/Text/Pandoc/Error.hs+3
@@ -62,6 +62,7 @@ data PandocError = PandocIOError Text IOError
6262 | PandocUnknownWriterError Text
6363 | PandocUnsupportedExtensionError Text Text
6464 | PandocCiteprocError CiteprocError
65+ | PandocBibliographyError Text Text
6566 deriving (Show, Typeable, Generic)
6667
6768instance Exception PandocError
@@ -143,6 +144,8 @@ handleError (Left e) =
143144 "for " <> f
144145 PandocCiteprocError e' -> err 24 $
145146 prettyCiteprocError e'
147+ PandocBibliographyError fp msg -> err 25 $
148+ "Error reading bibliography file " <> fp <> ":\n" <> msg
146149
147150err :: Int -> Text -> IO a
148151err exitCode msg = do