jgm/pandocfilters

Any way to show Python errors?

Opened this issue · 5 comments

Hi - thanks for this library.

I'm wondering if there's a way to capture python errors or output that python would be sending to stdout and display that if something goes wrong, rather than some of the less-than-helpful errors I've been getting back.

Often, there's a terminateProcess: permission denied (Permission denied) (when you try to print() something within your py script) or a callstack error:

CallStack (from HasCallStack):
  error, called at pandoc.hs:144:42 in main:Main

It would be immensely helpful in groking how to use the library's syntax.

ickc commented

It won't be possible, because as far as pandocfilters (in Python) is concerned, it has no error.

pandocfilters is for you to modify the JSON. Now, once the JSON is modified (while still being a valid JSON and pandocfilters' job is done), that JSON may no longer be a valid pandoc AST. And hence when pandoc parse the JSON (after obtaining it back from a pandocfilters), pandoc (in Haskell) complain.

There's however an issue on pandoc that propose pandoc to emit more meaningful error messages. And I believe it's in @jgm todo list. So I believe this issue should be closed.

As a sidenote, you should consider sergiocorreia/panflute: An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions. panflute parses the JSON from pandoc to an internal panflute AST which mimics pandoc's AST, which Python classes. So there's a lot of checking in panflute to guarantee your output is correct. While it isn't perfect (in the sense that it can catch all malformed pandoc AST before emitting a JSON), it will provide much more helpful hints for debugging. If you go to pandoc-discuss, @jgm also recommend panflute.

jgm commented

@benpolinsky errors sent to stderr should be streamed through.

jgm commented

We could change pandoc so that, if the script returns an error status, stdout is sent to the terminal.
The problem is that in some scripts, stdout (even with error status) may be a full or partial JSON object, not the kind of thing that would be helpful as an error message.

ickc commented

We could change pandoc so that, if the script returns an error status, stdout is sent to the terminal.
The problem is that in some scripts, stdout (even with error status) may be a full or partial JSON object, not the kind of thing that would be helpful as an error message.

I'm kind of confused. I thought he's talking about the error in Haskell, not in Python. And if he's talking about printing some debug messages solely for debugging purpose, then would he just pipe it through like pandoc -t json ... | filter?

Often, there's a terminateProcess: permission denied (Permission denied) (when you try to print() something within your py script) or a callstack error:

CallStack (from HasCallStack):
error, called at pandoc.hs:144:42 in main:Main

I think may be @benpolinsky should give some Minimal (not-)Working Example for the errors and what you expect.

Ah apologies for the lack of communication. I haven't been working with Pandoc for the last week or so and my github notifications were out of control.

I'll double back and produce an example when I get a chance in the next couple of days.