eprovst / wrap

A Fountain export tool with some extras...
GNU General Public License v3.0
62 stars 8 forks source link

panic: index out of range error with underscore, full stop, eol #36

Closed rnkn closed 4 years ago

rnkn commented 4 years ago

Describe the bug

Wrap will error trying to generate a PDF if the input Fountain file contains a line ending with _.

To Reproduce

Steps to reproduce the behavior:

  1. wrap pdf INPUT.fountain
  2. See error

Given the following example:

Clark's other hand. He loosens his grip. _Lets go of the rope_.

Command wrap pdf INPUT.fountain results in the following:

panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/Wraparound/wrap/pdf.wordwrap(0xc00005c4e0, 0x3, 0x4, 0x2, 0x11e3f
6b, 0xc000020240, 0x128a33d)
        /home/elecprog/Development/wrap/pdf/wordwrap.go:53 +0xb16
github.com/Wraparound/wrap/pdf.cellify(0xc00000c380, 0x1, 0x1, 0xc000020502,
 0x128a33d, 0x7, 0x3)
        /home/elecprog/Development/wrap/pdf/cellifying.go:44 +0xc9
github.com/Wraparound/wrap/pdf.sectionize(0x12d8880, 0xc00000c3a0, 0x0, 0x0,
 0x0, 0x0, 0x0)
        /home/elecprog/Development/wrap/pdf/sectionize.go:27 +0x1a7f
github.com/Wraparound/wrap/pdf.buildPDF(0xc000010bd0, 0x10a9f66, 0x5e1ada94,
 0xc02c6280c8)
        /home/elecprog/Development/wrap/pdf/pdf.go:104 +0x53a
github.com/Wraparound/wrap/pdf.WritePDF(0xc000010bd0, 0x12d8140, 0xc00002020
0, 0xc0000da000, 0xc00000e0d8)
        /home/elecprog/Development/wrap/pdf/files.go:35 +0x2b
github.com/Wraparound/wrap/cli.export(0xc0000508e0, 0x1, 0x1, 0x1289937, 0x3
, 0x12999b0)
        /home/elecprog/Development/wrap/cli/export.go:62 +0x276
github.com/Wraparound/wrap/cli.pdfRun(0x1466cc0, 0xc0000508e0, 0x1, 0x1)
        /home/elecprog/Development/wrap/cli/pdf.go:88 +0x3c5
github.com/spf13/cobra.(*Command).execute(0x1466cc0, 0xc0000508b0, 0x1, 0x1,
 0x1466cc0, 0xc0000508b0)
        /home/elecprog/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:7
66 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x1466f20, 0xc000042750, 0xc00007
af50, 0x100535f)
        /home/elecprog/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:8
52 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
        /home/elecprog/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:8
00
main.main()
        /home/elecprog/Development/wrap/wrap.go:15 +0x31

Expected behavior

PDF output generated.

Version

Additional context

The error can be worked around by switching the underscore and full stop, i.e.

_Lets go of the rope._

However, I tend to write it the other way around, for aesthetic considerations.

rnkn commented 4 years ago

p.s. Also, is it odd that your personal home directory path is included in the error message?

eprovst commented 4 years ago

Go seems to use the path at compile time for it's error messages, a bit strange indeed. However, a program shouldn't crash... I'll take a look :slightly_smiling_face:

eprovst commented 4 years ago

Ok I have located the error and (partially) fixed it.

This highlights a fairly important issue with the word wrap algorithm. It now moves the full stop to a new line as it only checks within one 'cell' (part of text with a certain markup). I'll see if I can rework it.

eprovst commented 4 years ago

Interesting, your issue has nothing to do with the few quirks of the current algorithm. You were simply unfortunate enough to write a line which ends with a 'cell' of length one and that cell being the 'one character too many' for the line.

Fixed that now, I'll release this as a hotfix :slightly_smiling_face:

rnkn commented 4 years ago

Very impressed at your response time!

I’m not sure if it’s worth mentioning, if it perhaps differs from your hotifx, but I had a script where this occurred in two locations, the one already mentioned on an action line, and the other within dialogue:


TEO
Tatara naspirit saura ba. _Tatara duwindu_.

(Yes it’s another language 😉)

rnkn commented 4 years ago

p.s. I just built from master and the error is fixed for me, thanks 👍