benbria / browserify-transform-tools

Utilities for writing browserify transforms.
MIT License
65 stars 15 forks source link

forward falafel errors #2

Closed bodokaiser closed 10 years ago

bodokaiser commented 10 years ago

I think you forget to emit an error event somewhere (may be somewhere here?)[https://github.com/benbria/browserify-transform-tools/blob/master/src/transformTools.coffee#L157] .

At least my node process crashes when having a syntax error whereas I get an error event on the builder to handle.

Error: Line 5: Unexpected token ILLEGAL (while aliasify was processing /Users/bodokaiser/Documents/Repositories/satisfeet/app/index.js)
    at throwError (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1472:21)
    at scanPunctuator (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:689:9)
    at advance (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1065:16)
    at lex (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1076:21)
    at consumeSemicolon (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1589:13)
    at parseVariableStatement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:2295:9)
    at parseStatement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:2826:24)
    at /Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3588:38
    at parseSourceElement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3068:24)
    at parseSourceElements (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3106:29)
make: *** [boot] Error 8
jwalton commented 10 years ago

The "(while aliasify was processing..." is added right before we call emit here:

https://github.com/benbria/browserify-transform-tools/blob/master/src/transformTools.coffee#L76

What do you mean by getting an error event on the builder?

bodokaiser commented 10 years ago

For example here browserify emits an error event. This allows using something like:

app.use(function(req, res, next) {
    var builder = browserify();
    var writer = getFileStream();

    builder.on('error', next);
    writer.on('finish', next);
});

in development mode I then would get a http 500 response and can easily fix the typo else I always have to restart the daemon as node crashes (which is not so nice if there should be an error in production).

jwalton commented 10 years ago

I added this unit test and this unit test, and both pass the way I'd expect them to.

I started working on a unit test that actually uses browserify (and found a bug in the latest browserify :P), but I found I'd get the error in the bundle() callback, but not in my error handler. I notice that the browserify docs don't mention an error event, although you plainly found one in the source. :/

jwalton commented 10 years ago

That code example you gave me isn't complete, yes? I mean, I don't see where you actually call into browserify... Do you have a more complete example I can try out?

bodokaiser commented 10 years ago

I found my mistake: The error event is emitted on the stream which is returned by bundle() not on browserify() itself ^^

Sry should have tried this before...

jwalton commented 10 years ago

No worries. It forced me to write some more unit tests, which isn't a bad thing. ;) On Dec 29, 2013 9:33 AM, "Bodo Kaiser" notifications@github.com wrote:

I found my mistake: The error event is emitted on the stream which is returned by bundle() not on browserify() itself ^^

Sry should have tried this before...

— Reply to this email directly or view it on GitHubhttps://github.com/benbria/browserify-transform-tools/issues/2#issuecomment-31317964 .

bodokaiser commented 10 years ago

Glad it was not totally useless though its generally a bad thing searching mistakes at others :)

However think this was the last time :p

Am 29.12.2013 um 15:46 schrieb Jason Walton notifications@github.com:

No worries. It forced me to write some more unit tests, which isn't a bad thing. ;) On Dec 29, 2013 9:33 AM, "Bodo Kaiser" notifications@github.com wrote:

I found my mistake: The error event is emitted on the stream which is returned by bundle() not on browserify() itself ^^

Sry should have tried this before...

— Reply to this email directly or view it on GitHubhttps://github.com/benbria/browserify-transform-tools/issues/2#issuecomment-31317964 .

— Reply to this email directly or view it on GitHub.