Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lookupMetaBlocks allows loss of data without error reporting #10634

Open
andrewufrank opened this issue Feb 21, 2025 · 1 comment
Open

lookupMetaBlocks allows loss of data without error reporting #10634

andrewufrank opened this issue Feb 21, 2025 · 1 comment
Labels

Comments

@andrewufrank
Copy link

Explain the problem.
The function lookupMetaBlocks is not producing an error when it fails to convert whatever found to blocks. The code in pandoc 3.6.3 is:

-- | Retrieve the metadata value for a given @key@
-- and extract blocks.
lookupMetaBlocks :: Text -> Meta -> [Block]
lookupMetaBlocks key meta =
  case lookupMeta key meta of
         Just (MetaBlocks bs)   -> bs
         Just (MetaInlines ils) -> [Plain ils]
         Just (MetaString s)    -> [Plain [Str s]]
         _                      -> []

If the value retrieved has type MetaList [..] then the value is silently lost with _ -> []

I would recommend to produce a suitable error message, eventhough such a case does not occur within the Pandoc code. -- I had constructed a value with a type of MetaList [MetaBlocks [Block]] which can be converted to [Block] but not withinlookupMetaBlocks`; an error message would have drawn my attention to the problem, finding the cause for the unexplained data loss was more difficult.

Pandoc version?
pandoc 3.6.3 on linux (debian bookworm), ghc 9.10.1

@jgm
Copy link
Owner

jgm commented Feb 21, 2025

Well, none of these lookupMeta... functions return a type that could hold an error, so this would require changing all the types and checking for the error status in the calling sites.

If you want something fancier, it is of always possible to use lookupMeta and do the pattern matching yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants