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

panflute.yaml_filter: error handling when YAML is invalid #23

Closed
ickc opened this issue Nov 20, 2016 · 4 comments
Closed

panflute.yaml_filter: error handling when YAML is invalid #23

ickc opened this issue Nov 20, 2016 · 4 comments

Comments

@ickc
Copy link
Collaborator

ickc commented Nov 20, 2016

I'm writing a test on invalid YAML:

``` {.table}
---
caption: *unquoted*
...
1,2
3,4
```

which would gives this error:

yaml.scanner.ScannerError: while scanning an alias
  in "<unicode string>", line 1, column 10:
    caption: *unquoted*
             ^
expected alphabetic or numeric character, but found '*'
  in "<unicode string>", line 1, column 19:
    caption: *unquoted*
                      ^

I'm thinking how to handle the error. May be an option can be given to panflute.yaml_filter such that it will do nothing (leave the code block as is) rather than raising an error?

@sergiocorreia
Copy link
Owner

I agree that Python errors should not be allowed to occur.

We could just wrap the YAML reader in a try ... except code, and if it fails, then do nothing but issue a warning message?

@ickc
Copy link
Collaborator Author

ickc commented Nov 21, 2016

In addition to a warning message in command-line, how about it returns the options with only 1 key, say, {'yaml-error': True}, so that individual filters can decide how to deal with it? (e.g. One can continue to work with the data while ignoring the options with "sensible defaults".)

By the way, I tested invalid YAML in pandoc and it will do:

$ printf "%s\n" '---' 'title: *unquoted*' '---' '' 'non-empty' | pandoc -f markdown -t native --css=abc.css
pandoc: Could not parse YAML header: did not find expected alphabetic or numeric character "source" (line 3, column 17)
Pandoc (Meta {unMeta = fromList []})
[Para [Str "non-empty"]]

@sergiocorreia
Copy link
Owner

sergiocorreia commented Nov 22, 2016

I wrote the code for the soft error handling, but I think that at least for now the better alternative is not to run the filter at all:

  • It would allow the reader of the output to inspect what went wrong (you can just read the code block)
  • The errors would be harder to spot (e.g. a table might have the wrong title, instead of just appearing as a code block)
  • It would add even more complexity to the YAML filter

@ickc
Copy link
Collaborator Author

ickc commented Nov 23, 2016

I finished my filter in ickc/pantable: CSV Tables in Markdown: Pandoc Filter for CSV Tables. It's based on your csv example but eventually breaks compatibility with it.

One potential problem is exactly what you said above: I handle away all errors in the YAML metadata and override them with "sensible defaults".

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

No branches or pull requests

2 participants