public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Signalling error from Python filter
@ 2019-10-18 11:14 Björn Stenborg
       [not found] ` <3241f1a9-fee2-4203-a070-612fed71c963-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Björn Stenborg @ 2019-10-18 11:14 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1671 bytes --]

Hi! I'm trying to figure out how best to signal errors from a Python Pandoc 
filter. If I detect that something goes wrong during filter execution, the 
goal is to print a descriptive error message to the console and then return 
an error indication. Unfortunately I can't figure out how to pass that 
through Pandoc.

I could either let my filter print the error to the console and then signal 
back to Pandoc that document generation should be aborted, or if possible 
return an error message to Pandoc and have Pandoc propagate it up to the 
script calling the pandoc binary. But throwing an exception containing the 
error message leaves me with a not very user-friendly call trace in the 
console that obscures the real error message. I can't find any real 
documentation of error codes produced by Pandoc and my Haskell skills are 
atrocious so I'm having a hard time reading the code I'm afraid.

I have an ugly workaround in embedding the error message within a custom 
"tag" in the generated document and then having the document generation 
script outside pandoc look for that tag in the generated document and 
present the error message that it contains and report the document 
generation as failed to the build system. But this is awkward.

Ideas?

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/3241f1a9-fee2-4203-a070-612fed71c963%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 2082 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Signalling error from Python filter
       [not found] ` <3241f1a9-fee2-4203-a070-612fed71c963-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-10-18 17:36   ` BPJ
       [not found]     ` <CADAJKhDQz69H7Htx5muDPPB77C6uC=fQnhkmTz2fqXhVE_7Y5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-10-19  7:13   ` Kolen Cheung
  1 sibling, 1 reply; 4+ messages in thread
From: BPJ @ 2019-10-18 17:36 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2660 bytes --]

Have you tried to just throw an exception or print a message to stderr? As
far as I know pandoc will forward it to its own stderr in an orderly
manner, unless the python filter library you are using does something funny.


Den fre 18 okt. 2019 13:15Björn Stenborg <bjorn.stenborg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> Hi! I'm trying to figure out how best to signal errors from a Python
> Pandoc filter. If I detect that something goes wrong during filter
> execution, the goal is to print a descriptive error message to the console
> and then return an error indication. Unfortunately I can't figure out how
> to pass that through Pandoc.
>
> I could either let my filter print the error to the console and then
> signal back to Pandoc that document generation should be aborted, or if
> possible return an error message to Pandoc and have Pandoc propagate it up
> to the script calling the pandoc binary. But throwing an exception
> containing the error message leaves me with a not very user-friendly call
> trace in the console that obscures the real error message. I can't find any
> real documentation of error codes produced by Pandoc and my Haskell skills
> are atrocious so I'm having a hard time reading the code I'm afraid.
>
> I have an ugly workaround in embedding the error message within a custom
> "tag" in the generated document and then having the document generation
> script outside pandoc look for that tag in the generated document and
> present the error message that it contains and report the document
> generation as failed to the build system. But this is awkward.
>
> Ideas?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/3241f1a9-fee2-4203-a070-612fed71c963%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/3241f1a9-fee2-4203-a070-612fed71c963%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDQz69H7Htx5muDPPB77C6uC%3DfQnhkmTz2fqXhVE_7Y5Q%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 3489 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Signalling error from Python filter
       [not found] ` <3241f1a9-fee2-4203-a070-612fed71c963-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-10-18 17:36   ` BPJ
@ 2019-10-19  7:13   ` Kolen Cheung
  1 sibling, 0 replies; 4+ messages in thread
From: Kolen Cheung @ 2019-10-19  7:13 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 973 bytes --]

A few suggestions:

- try panflute instead of pandocfilters. Panflute is more pythonic and even jgm recommended it. It for example parse the JSON from pandoc to an AST representation in Python. It emits much better error message when things break

- if you think some errors are too severe and should break immediately, try to exit your Python program on top of printing error message. Pandoc filter is just a Unix filter so if you break your program that doesn’t pass pandoc back a valid json representation of the AST then pandoc cannot process it.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/dbd86cc3-82e0-46b8-bbbc-9d07182d7298%40googlegroups.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Signalling error from Python filter
       [not found]     ` <CADAJKhDQz69H7Htx5muDPPB77C6uC=fQnhkmTz2fqXhVE_7Y5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-10-21  5:42       ` John MacFarlane
  0 siblings, 0 replies; 4+ messages in thread
From: John MacFarlane @ 2019-10-21  5:42 UTC (permalink / raw)
  To: BPJ, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


This is correct. Print to stderr -- that will be passed on -- and
return an error status (non-0).  Then pandoc will, in addition,
indicate that the filter failed and exit with an error status.

BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Have you tried to just throw an exception or print a message to stderr? As
> far as I know pandoc will forward it to its own stderr in an orderly
> manner, unless the python filter library you are using does something funny.
>
>
> Den fre 18 okt. 2019 13:15Björn Stenborg <bjorn.stenborg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>
>> Hi! I'm trying to figure out how best to signal errors from a Python
>> Pandoc filter. If I detect that something goes wrong during filter
>> execution, the goal is to print a descriptive error message to the console
>> and then return an error indication. Unfortunately I can't figure out how
>> to pass that through Pandoc.
>>
>> I could either let my filter print the error to the console and then
>> signal back to Pandoc that document generation should be aborted, or if
>> possible return an error message to Pandoc and have Pandoc propagate it up
>> to the script calling the pandoc binary. But throwing an exception
>> containing the error message leaves me with a not very user-friendly call
>> trace in the console that obscures the real error message. I can't find any
>> real documentation of error codes produced by Pandoc and my Haskell skills
>> are atrocious so I'm having a hard time reading the code I'm afraid.
>>
>> I have an ugly workaround in embedding the error message within a custom
>> "tag" in the generated document and then having the document generation
>> script outside pandoc look for that tag in the generated document and
>> present the error message that it contains and report the document
>> generation as failed to the build system. But this is awkward.
>>
>> Ideas?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pandoc-discuss/3241f1a9-fee2-4203-a070-612fed71c963%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/3241f1a9-fee2-4203-a070-612fed71c963%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDQz69H7Htx5muDPPB77C6uC%3DfQnhkmTz2fqXhVE_7Y5Q%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2k18yu00s.fsf%40johnmacfarlane.net.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-21  5:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-18 11:14 Signalling error from Python filter Björn Stenborg
     [not found] ` <3241f1a9-fee2-4203-a070-612fed71c963-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-10-18 17:36   ` BPJ
     [not found]     ` <CADAJKhDQz69H7Htx5muDPPB77C6uC=fQnhkmTz2fqXhVE_7Y5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-10-21  5:42       ` John MacFarlane
2019-10-19  7:13   ` Kolen Cheung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).