CLI does not show location of syntax error when --stacktrace option is specified
When the --stacktrace CLI option is specified, and there's a syntax error in a file Antora is attempting to require, the stacktrace does not show the location of that error. This happens because the stack of the SyntaxError object has a different structure than other Error types. In a SyntaxError, the location and line information is stored above the message and cause. The CLI will need to account for this and rearrange the lines so that it can show the full context.
Here's an example of a stack of a SyntaxError:
/path/to/playbook/asciidoctor-ext.js:6
console.log(doc.getDocumentTitle()
^
SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at userRequire (.../@antora/user-require-helper/lib/index.js:42:10)
at extensions.reduce (.../@antora/asciidoc-loader/lib/load-asciidoc.js:174:25)
at Array.reduce (<anonymous>)
Here's how we want the error to appear when Antora is run:
SyntaxError: missing ) after argument list
at /path/to/playbook/asciidoctor-ext.js:6
console.log(doc.getDocumentTitle()
^
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at userRequire (.../@antora/user-require-helper/lib/index.js:42:10)
at extensions.reduce (.../@antora/asciidoc-loader/lib/load-asciidoc.js:174:25)
at Array.reduce (<anonymous>)