Skip to content

Commit 2530422

Browse files
committed
Give better position information when YAML metadata parsing fails...
with a YAML exception. See #10231.
1 parent dbe2495 commit 2530422

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Text/Pandoc/Readers/Metadata.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ yamlBsToMeta :: (PandocMonad m, HasLastStrPosition st)
4444
-> B.ByteString
4545
-> ParsecT Sources st m (Future st Meta)
4646
yamlBsToMeta pMetaValue bstr = do
47+
pos <- getPosition
4748
case decodeAllWithWarnings bstr of
4849
Right (warnings, xs) -> do
49-
pos <- getPosition
5050
mapM_ (\(Yaml.DuplicateKey jpath) ->
5151
report (YamlWarning pos $ "Duplicate key: " <>
5252
T.pack (formatRelativePath jpath)))
@@ -57,7 +57,9 @@ yamlBsToMeta pMetaValue bstr = do
5757
[] -> return . return $ mempty
5858
_ -> Prelude.fail "expected YAML object"
5959
Left err' -> do
60-
let msg = T.pack $ Yaml.prettyPrintParseException err'
60+
let msg = T.pack $ "Error parsing YAML metadata at " <>
61+
show pos <> ":\n" <>
62+
Yaml.prettyPrintParseException err'
6163
throwError $ PandocParseError $
6264
if "did not find expected key" `T.isInfixOf` msg
6365
then msg <>

0 commit comments

Comments
 (0)