Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exceptions causes a silent exit #610

Closed
Xenonym opened this issue Jan 20, 2019 · 3 comments
Closed

Uncaught exceptions causes a silent exit #610

Xenonym opened this issue Jan 20, 2019 · 3 comments

Comments

@Xenonym
Copy link
Contributor

Xenonym commented Jan 20, 2019

Tell us about your environment

  • MarkBind Version: 1.16.1

What did you do? Please include the actual source code causing the issue.
If an exception is thrown that is not handled, MarkBind logs the exception but does not return anything to standard output. For example, suppose we have the following MarkBind source:

<!-- the following will cause an exception in Nunjucks -->
{% set error = " %}

What did you expect to happen?
MarkBind should print the exception to standard output / error, or at least indicate to the user that they should investigate the log file for more information.

What actually happened? Please include the actual, raw output.
markbind build aborts halfway with no feedback:

PS C:\Users\pzy5a\Desktop\testbind> markbind build
  __  __                  _      ____    _               _
 |  \/  |   __ _   _ __  | | __ | __ )  (_)  _ __     __| |
 | |\/| |  / _` | | '__| | |/ / |  _ \  | | | '_ \   / _` |
 | |  | | | (_| | | |    |   <  | |_) | | | | | | | | (_| |
 |_|  |_|  \__,_| |_|    |_|\_\ |____/  |_| |_| |_|  \__,_|

 v1.16.1
info: Website generation started at 18:13:12
info: Building assets...
info: Assets built
info: Generating pages...
[-] 0 / 1 pages built
PS C:\Users\pzy5a\Desktop\testbind>

However, the exception is logged:

2019-01-20T10:13:12.451Z - error: uncaughtException: (unknown path)
  expected block end in set statement date=Sun Jan 20 2019 18:13:12 GMT+0800 (Malay Peninsula Standard Time), pid=18160, uid=null, gid=null, cwd=C:\Users\pzy5a\Desktop\testbind, execPath=C:\Program Files\nodejs\node.exe, version=v8.15.0, argv=[C:\Program Files\nodejs\node.exe, C:\Program Files\nodejs\node_modules\markbind-cli\index.js, build], rss=63217664, heapTotal=60190720, heapUsed=26615736, external=836159, loadavg=[0, 0, 0], uptime=165999
Template render error: (unknown path)
  expected block end in set statement
    at Object.exports.prettifyError (C:\Users\pzy5a\Documents\GitHub\CS3281-2\markbind\node_modules\nunjucks\src\lib.js:34:15)
    at new_cls.render (C:\Users\pzy5a\Documents\GitHub\CS3281-2\markbind\node_modules\nunjucks\src\environment.js:472:27)
    at new_cls.renderString (C:\Users\pzy5a\Documents\GitHub\CS3281-2\markbind\node_modules\nunjucks\src\environment.js:328:21)
    at Object.module.exports.renderString (C:\Users\pzy5a\Documents\GitHub\CS3281-2\markbind\node_modules\nunjucks\index.js:80:14)
    at fs.readFile (C:\Users\pzy5a\Documents\GitHub\CS3281-2\markbind\src\lib\markbind\src\parser.js:416:36)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
@Xenonym
Copy link
Contributor Author

Xenonym commented Jan 20, 2019

Related to #265, but we should also solve the more general case of not surfacing anything when an uncaught exception is thrown.

@amad-person
Copy link
Contributor

This behaviour is most likely because of a bug in Nunjucks. Errors were being swallowed on synchronous rendering. A fix was added by this PR in Nunjucks v3.1.7.

I installed Nunjucks 3.1.7 but markbind build still fails silently on adding a statement like {% set error = " %}.

I also tried configuring Nunjucks by adding nunjucks.configure({ throwOnUndefined: true }) in Site.js, Page.js and parser.js. This didn't throw an error too.

Apparently the errors were not being swallowed on asynchronous renders, so I tried adding callbacks in nunjucks.renderString() to handle errors (syntax) but I got the following:

(node:29797) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 logged listeners added. Use emitter.setMaxListeners() to increase limit
(node:29797) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit

Does anyone know how to fix this?
Or has another approach to handle errors thrown by nunjucks?

@Xenonym
Copy link
Contributor Author

Xenonym commented Feb 20, 2019

@amad-person not sure if its a Nunjucks problem: the fact that the exception is logged means that Nunjucks is throwing the error (since otherwise the error can't be logged). I suspect it might be the logger (winston@2.4.4) that's swallowing the error after logging it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants