LaurentRDC / pandoc-plot

Render and include figures in Pandoc documents using your plotting toolkit of choice
https://laurentrdc.github.io/pandoc-plot/
GNU General Public License v2.0
216 stars 8 forks source link

Better error processing & message when output format string is in lower caps. #42

Closed mfhepp closed 2 years ago

mfhepp commented 2 years ago

The output format string in a pandoc-plot configuration YAML file must be in upper case, because that is what Haskell seems to expect. Unfortunately, making a mistake here leads to hard-to-debug errors:

In a typical tool-chain, pandoc-plot will only fail to load the settings - but this is hard to spot in some cases, e.g. if it silently uses another path for the binaries of the toolkits.

It was only when I tried this command

$ pandoc-plot toolkits --config ~/myproject/pandoc-plot-settings.yaml

that I found the true cause:


pandoc-plot: Could not convert to expected type: Error in $.format: parsing 
Text.Pandoc.Filter.Plot.Monad.Types.SaveFormat 
failed, expected one of the tags ["PNG","PDF","SVG","JPG","EPS","GIF","TIF",
"WEBP","HTML","LaTeX"], but found tag "png"
CallStack (from HasCallStack):
  error, called at src/Data/Yaml/Config.hs:215:19 in yml-0.11.7.0-3e357bc6:Data.Yaml.Config

So bottom-line:

  1. The output format identifiers in pandoc-plot configuration files must be all upper-case! Like so
# Default format in which to save the figures. This can be specified
# individually as well.
format: PNG
  1. It would be really good to make the code more tolerant and/or throw more informative error messages, ideally both :-).
LaurentRDC commented 2 years ago

Yes that makes sense. This is an easy change; a hand-written instance of FromJSON SaveFormat needs to be implemented, rather than the one derived from Generic.

Do you feel up for putting together as PR for this? I don't have much time these days

LaurentRDC commented 2 years ago

I've made the parsing of save format from configuration as flexible as 'inline' format specification. For example, png, PNG, and .png are considered equivalent.

This fix will be available in the next release. Thank you for submitting this issue!

LaurentRDC commented 2 years ago

Version 1.5.0 was just released, which includes this fix. It might take a few hours for executables to be uploaded to GitHub Releases.