public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* “PANIC” error message with custom writer
@ 2014-12-20 21:07 Gordon Steemson
       [not found] ` <fc67fe32-8b42-4ba3-9ef5-a072a47fd8d9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Gordon Steemson @ 2014-12-20 21:07 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


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

Hi all,

I am using Pandoc (by way of a Perl script called from within TextWrangler 
on Mac OS 10.6.8) to publish my amateurish scribblings to a variety of fan 
fiction repositories on the Web. All of them bar my own personal site use 
an extremely crippled subset of HTML with no stylesheet support as an input 
format, and just to make things extra fun, the nature of the HTML crippling 
varies from repository to repository. This is easily gotten around in 
theory by making a custom writer for each repository, but the first one I 
tried (for fanfiction.net) is giving me serious and intractable problems.

First was the fact that nowhere is it apparently documented what directory 
the “-t path/to/custom_writer.lua” is relative to (it definitely isn’t the 
same directory the “templates” folder lives in), and using “~” as an 
abbreviation for my home directory is apparently not supported. I finally 
got around that one by specifying an absolute path from the root of my 
filesystem, which seems unnecessarily fragile and inflexible.

Second, when I FINALLY got the damn thing to actually try to call the 
custom writer, it immediately bombed out with the following error message:

>
> PANIC: unprotected error in call to Lua API (attempt to call a string 
value)
>

This is… less than informative. Does anyone have any idea what’s going on 
here? I went over my modifications to the sample.lua file and I can’t find 
anything very different from what was supplied initially—my changes were 
almost all cosmetic, of the “turn an insertion of unsupported HTML tag X 
into an insertion of <p> (or <b>, or whatever)” variety. In the absence of 
more helpful diagnostic messages, I am completely at a loss for how to 
proceed.

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/fc67fe32-8b42-4ba3-9ef5-a072a47fd8d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: “PANIC” error message with custom writer
       [not found] ` <fc67fe32-8b42-4ba3-9ef5-a072a47fd8d9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2014-12-20 21:56   ` Gordon Steemson
       [not found]     ` <8b9ae12c-20fe-4381-bf71-1394e301f902-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2014-12-22 16:35   ` John MacFarlane
  1 sibling, 1 reply; 8+ messages in thread
From: Gordon Steemson @ 2014-12-20 21:56 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


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

I tried the same Pandoc command line with the sample.lua file and it 
worked, so it’s definitely something wrong in my custom writer. Now how do 
I debug that?

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/8b9ae12c-20fe-4381-bf71-1394e301f902%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: “PANIC” error message with custom writer
       [not found]     ` <8b9ae12c-20fe-4381-bf71-1394e301f902-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2014-12-21  7:32       ` Gordon Steemson
       [not found]         ` <5ea323ef-4f59-48ef-9280-9514543453b5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Gordon Steemson @ 2014-12-21  7:32 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


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

I can say that the Lua compiler processes my writer with no issues. Is this 
a problem with Lua error handling in Pandoc?

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5ea323ef-4f59-48ef-9280-9514543453b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: “PANIC” error message with custom writer
       [not found] ` <fc67fe32-8b42-4ba3-9ef5-a072a47fd8d9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2014-12-20 21:56   ` Gordon Steemson
@ 2014-12-22 16:35   ` John MacFarlane
  1 sibling, 0 replies; 8+ messages in thread
From: John MacFarlane @ 2014-12-22 16:35 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

The erorr message you're getting,

>> PANIC: unprotected error in call to Lua API (attempt to call a string
>value)

means that you're using a variable that actually has a string value
as if it's a function value.  Example of the sort of thing that would
trigger this error:

    x = "hi"
    x(2)

Maybe this clue will help you to debug your script?  Look closely at
the places your script diverges from sample.lua.  Most likely you're
assigning a string somewhere that a function is expected.

>First was the fact that nowhere is it apparently documented what directory
>the “-t path/to/custom_writer.lua” is relative to (it definitely isn’t the
>same directory the “templates” folder lives in), and using “~” as an
>abbreviation for my home directory is apparently not supported. I finally
>got around that one by specifying an absolute path from the root of my
>filesystem, which seems unnecessarily fragile and inflexible.

You need to provide the path to the script (as usual for paths, this
is interpreted relative to the working directory).  As the User's Guide
says:

> To use a custom writer, simply specify the path to the lua script
> in place of the output format. For example:
>
>    pandoc -t data/sample.lua

Using `~` for home directory should work, if your shell supports this (this
part is interpreted by the shell's processing of the command-line
arguments, not by pandoc itself).

> % pandoc -t ~/src/pandoc/data/sample.lua
> hi
> <p>hi</p>

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/20141222163550.GC95411%40localhost.hsd1.nm.comcast.net.
For more options, visit https://groups.google.com/d/optout.


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

* Re: “PANIC” error message with custom writer
       [not found]         ` <5ea323ef-4f59-48ef-9280-9514543453b5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2014-12-22 16:37           ` John MacFarlane
       [not found]             ` <20141222163759.GD95411-bi+AKbBUZKaOwiQRAsGx7a+gxsCIUpAnHiGdP5j34PU@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2014-12-22 16:37 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

+++ Gordon Steemson [Dec 20 14 23:32 ]:
>I can say that the Lua compiler processes my writer with no issues. Is this
>a problem with Lua error handling in Pandoc?

luac will happily compile:

    x = "hi"
    x(2)

The error only gets detected at run time.  (Dynamic languages!)


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

* Re: “PANIC” error message with custom writer
       [not found]             ` <20141222163759.GD95411-bi+AKbBUZKaOwiQRAsGx7a+gxsCIUpAnHiGdP5j34PU@public.gmane.org>
@ 2015-01-19  2:39               ` Gordon Steemson
       [not found]                 ` <37f4d724-11e4-4104-abba-8388b88f1eaf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Gordon Steemson @ 2015-01-19  2:39 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


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

After extensive deletions resulting in a ‘writer’ that contained nothing 
but the utility function which tells you which functions are missing at run 
time, I have determined that my code was in fact flawless; the problem was 
that, in my enthusiasm for doing a thing properly, I had added a shebang 
(#!) line to the beginning of the script, without really thinking about it.

Since Lua supposedly treats every file as an independent “chunk” (to use 
the official term), I don’t understand why this should cause trouble, but 
if anyone else runs into a similar issue, at least now we know the fix is 
easy.

In the course of my investigations, I also discovered that Pandoc’s 
internal Lua engine is two revisions out of date. I know Lua 5.3 was only 
released last week, but it includes very basic UTF-8 support, so I was 
really looking forward to using it. Given that even 5.2 was never 
incorporated into Pandoc, I am not very optimistic about that.

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/37f4d724-11e4-4104-abba-8388b88f1eaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: “PANIC” error message with custom writer
       [not found]                 ` <37f4d724-11e4-4104-abba-8388b88f1eaf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-01-19  5:40                   ` John MacFarlane
       [not found]                     ` <20150119054005.GA5491-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2015-01-19  5:40 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Aha - so that was it.  We just use `loadstring` and `call`
to evaluate the custom script.  Apparently this doesn't
allow for shebang lines:

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> x,y = loadstring("#!/bin/sh")
> x
> print(x)
nil
> print(y)
[string "#!/bin/sh"]:1: unexpected symbol near '#'

Now that I know that loadstring doesn't raise an error,
but instead returns the error as a second value, I'm
going to revise the custom writer so that it will raise
an error when there's a problem with the script,
giving the error message lua provides.

As for the version, we use the hs-lua library:
https://hackage.haskell.org/package/hslua
I don't know if they have plans to upgrade to 5.2 or 5.3,
but you could always write them and ask.
I imagine it would be fairly straightforward.


+++ Gordon Steemson [Jan 18 15 18:39 ]:
>   After extensive deletions resulting in a ‘writer’ that contained
>   nothing but the utility function which tells you which functions are
>   missing at run time, I have determined that my code was in fact
>   flawless; the problem was that, in my enthusiasm for doing a thing
>   properly, I had added a shebang (#!) line to the beginning of the
>   script, without really thinking about it.
>   Since Lua supposedly treats every file as an independent “chunk” (to
>   use the official term), I don’t understand why this should cause
>   trouble, but if anyone else runs into a similar issue, at least now we
>   know the fix is easy.
>   In the course of my investigations, I also discovered that Pandoc’s
>   internal Lua engine is two revisions out of date. I know Lua 5.3 was
>   only released last week, but it includes very basic UTF-8 support, so I
>   was really looking forward to using it. Given that even 5.2 was never
>   incorporated into Pandoc, I am not very optimistic about that.
>
>   --
>   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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To post to this group, send email to
>   [2]pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To view this discussion on the web visit
>   [3]https://groups.google.com/d/msgid/pandoc-discuss/37f4d724-11e4-4104-
>   abba-8388b88f1eaf%40googlegroups.com.
>   For more options, visit [4]https://groups.google.com/d/optout.
>
>References
>
>   1. mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   2. mailto:pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   3. https://groups.google.com/d/msgid/pandoc-discuss/37f4d724-11e4-4104-abba-8388b88f1eaf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org?utm_medium=email&utm_source=footer
>   4. https://groups.google.com/d/optout

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/20150119054005.GA5491%40protagoras.berkeley.edu.
For more options, visit https://groups.google.com/d/optout.


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

* Re: “PANIC” error message with custom writer
       [not found]                     ` <20150119054005.GA5491-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
@ 2015-01-19  5:50                       ` John MacFarlane
  0 siblings, 0 replies; 8+ messages in thread
From: John MacFarlane @ 2015-01-19  5:50 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

With
https://github.com/jgm/pandoc/commit/ab8b00ea0c2b312d936ff9cfe076a104644e9210
we now have:

% dist/build/pandoc/pandoc -t my.lua README
pandoc: [string "my.lua"]:1: unexpected symbol near '#'

Which would have saved you a lot of time.
Thanks for reporting the difficulties you had!


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

end of thread, other threads:[~2015-01-19  5:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-20 21:07 “PANIC” error message with custom writer Gordon Steemson
     [not found] ` <fc67fe32-8b42-4ba3-9ef5-a072a47fd8d9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2014-12-20 21:56   ` Gordon Steemson
     [not found]     ` <8b9ae12c-20fe-4381-bf71-1394e301f902-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2014-12-21  7:32       ` Gordon Steemson
     [not found]         ` <5ea323ef-4f59-48ef-9280-9514543453b5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2014-12-22 16:37           ` John MacFarlane
     [not found]             ` <20141222163759.GD95411-bi+AKbBUZKaOwiQRAsGx7a+gxsCIUpAnHiGdP5j34PU@public.gmane.org>
2015-01-19  2:39               ` Gordon Steemson
     [not found]                 ` <37f4d724-11e4-4104-abba-8388b88f1eaf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-19  5:40                   ` John MacFarlane
     [not found]                     ` <20150119054005.GA5491-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
2015-01-19  5:50                       ` John MacFarlane
2014-12-22 16:35   ` John MacFarlane

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).