ifrost / afterwriting-labs

Post-processing for Fountain screenplays
http://www.afterwriting.com
227 stars 38 forks source link

Error while compiling .fountain file using the CLI #68

Closed noquierouser closed 7 years ago

noquierouser commented 7 years ago

The CLI utility is throwing the following error while trying to compile my fountain file:

02 $ afterwriting --config C:\\Users\\noqui\\awconfig.json --pdf --overwrite --source .\02.fountain
'afterwriting command line interface
www: http://afterwriting.com

Loading script: .\02.fountain
Loading config... C:\\Users\\noqui\\awconfig.json
Generating PDF .\02.pdf
C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:42
        for (var before = index - 1; before && !(lines[before].text); before--) {
                                                              ^

TypeError: Cannot read property 'text' of undefined
    at default_breaker (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:42:63)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:151:23)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)
    at break_lines (C:\Users\noqui\scoop\persist\nodejs\bin\node_modules\afterwriting\js\utils\fountain\liner.js:176:22)

Now, apparently this might be because of a setting in my settings file, because when I remove the --config argument the file compiles just fine.

My actual settings file is this:

{
  "print_profile": "a4",
  "print_title_page": true,
  "print_sections": true,
  "print_synopsis": true,
  "print_notes": true,
  "print_headers": true,
  "print_actions": true,
  "print_dialogues": true,
  "print_header": "",
  "print_footer": "",
  "print_watermark": "",
  "split_dialogue": false,
  "use_dual_dialogue": true,
  "double_space_between_scenes": false,
  "each_scene_on_new_page": false,
  "number_sections": true,
  "embolden_scene_headers": true,
  "scenes_numbers": "none",
  "show_page_numbers": true
}

But, after I removed print_title_page, print_header, print_footer, print_watermark, split_dialogue, double_space_between_scenes and each_scene_on_new_page, the file compiled without issues.

I don't know what might be triggering this error, but if necessary, I can provide my fountain file for testing.

ifrost commented 7 years ago

Thanks for reporting it. It'd be very helpful if you could attach a sample file. I'll try to have a look at it this weekend.

ifrost commented 7 years ago

I tried to reproduce it to no avail so I'll need a sample fountain file.

Line numbers in the stack trace you pasted seem to be off - what version are you using? Did you modify liner.js directly in node_modules by any chance?

noquierouser commented 7 years ago

@ifrost I'm using afterwriting 1.3.5 from releases section, but this happened too with the npm version (1.2.28).

Here's the file that it's giving me the issue.

Edit: Link deleted

ifrost commented 7 years ago

Thanks!

So the problem is with "split_dialogue" option. The way it works is: when splitting the script into pages it keeps dialogue as one block and tries to find first "breaking point"above (between action and when the dialogue starts).

Your script, however, has a very long dialogue, covering more than one page. In such case the logic for splitting falls short as it's not able to find the breaking point (there's no way to keep the dialog on one page without breaking it).

To fix it I added a check that if split_dialogue == false and no breaking line is found - it simply breaks at the end of the page.

Please check the latest version.

Note: I think it's still not ideal as in case of very long dialogues, ideally one would like to force breaking at the end of the page without having the "lookup" for a breaking line above the dialogue as it may leave the script with blank patches. The solution could be to have 3 different options for splitting dialogue (1 - forced, 2 - automatic with "CONTINUED/MORE", and 3 - "block" mode to keep the dialogue as one block if possible). At the moment if split_dialogue == false it works in (3) "block" mode, or when split_dialogue == true it splits automatically adding "CONTINUED/MORE" (2). There's not way to force the dialogue to always split wherever it falls on the page.

noquierouser commented 7 years ago

I can confirm it's working now. Thanks so much for the quick response and the awesome fixing. You even updated the npm package! 👍

Regarding your note, I think your approach might be suitable for the use cases you propose. But I think it may break retrocompatibility if the option values change so drastically. Also, maybe searching for double spaces, as I did in my script, might be useful for breaking long dialogs too.