-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Comments
Well, none of these If you want something fancier, it is of always possible to use |
I was simply thinking to replace the last line with My issue was not with the functionality - this is easily done in a program - but with the silent discarding of data, which is hard to trace. A hard error would be helpful, when the function cannot achieve what it description says. I cannot see a use where a value retrieved can be converted to blocks but not by this code and the programmer would rely on the silent discarding; I rather believe that the input I had is beyond the inputs the function is designed for and an error message warranted. Thank you for your effort to maintain a wonderful tool! |
It's considered bad practice to use |
Completely agree! I think throwing away data silently is nothing a programmer assumes. The signature of the function allows legal values (e.g. |
No -- the programmer did foresee such cases. The intent of the function is: convert this metadata field to Blocks, if it has the right shape, otherwise return an empty list. Returning an empty list for MetaList is exactly what the function was designed to do. So putting an If it is desirable to indicate an error when the field is not of the right shape to convert to Blocks, then the right way to handle that would be to rewrite the function (a) to return an Either value or (b) to return a value in an instance of PandocMonad. Both changes would make this function less convenient to use in the cases where it was designed to be used. That's why I'm not inclined to do it. If you want different behavior for your own purposes, it's easy enough to write your own wrapper around Adding something to the haddock comment would be fine. |
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: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 within
lookupMetaBlocks`; 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
The text was updated successfully, but these errors were encountered: