Skip to content

Commit

Permalink
Add helpful message on some metadata YAML errors.
Browse files Browse the repository at this point in the history
Closes #9155.
  • Loading branch information
jgm committed Oct 23, 2023
1 parent a7756b9 commit 7115edf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Text/Pandoc/Readers/Metadata.hs
Expand Up @@ -31,7 +31,6 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition
import Text.Pandoc.Error
import Text.Pandoc.Parsing hiding (tableWith, parse)

import qualified Text.Pandoc.UTF8 as UTF8

yamlBsToMeta :: (PandocMonad m, HasLastStrPosition st)
Expand All @@ -45,8 +44,12 @@ yamlBsToMeta pMetaValue bstr = do
Right [Null] -> return . return $ mempty
Right _ -> Prelude.fail "expected YAML object"
Left err' -> do
throwError $ PandocParseError
$ T.pack $ Yaml.prettyPrintParseException err'
let msg = T.pack $ Yaml.prettyPrintParseException err'
throwError $ PandocParseError $
if "did not find expected key" `T.isInfixOf` msg
then msg <>
"\nConsider enclosing the entire field in 'single quotes'"
else msg

-- Returns filtered list of references.
yamlBsToRefs :: (PandocMonad m, HasLastStrPosition st)
Expand All @@ -69,9 +72,8 @@ yamlBsToRefs pMetaValue idpred bstr =
mapM (yamlToMetaValue pMetaValue) (filter hasSelectedId refs)
_ -> return $ return []
Right _ -> return . return $ []
Left err' -> do
throwError $ PandocParseError
$ T.pack $ Yaml.prettyPrintParseException err'
Left err' -> throwError $ PandocParseError
$ T.pack $ Yaml.prettyPrintParseException err'

normalizeMetaValue :: (PandocMonad m, HasLastStrPosition st)
=> ParsecT Sources st m (Future st MetaValue)
Expand Down

0 comments on commit 7115edf

Please sign in to comment.