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

Added logError function (Closes #121) #130

Closed
wants to merge 4 commits into from
Closed

Added logError function (Closes #121) #130

wants to merge 4 commits into from

Conversation

tomsotte
Copy link

Closes #121

Add an handy logError function that pretty-prints the error.
It emits 'end' to prevent exiting gulp abruptly. This is particularly useful for watching task, to not end them on every error.


Output example when compiling a .js file with an error:

With logError:

[13:20:46] Using gulpfile D:\workspace\source\test-gulp-babel\gulpfile.js
[13:20:46] Starting 'babel'...
SyntaxError in plugin 'gulp-babel'
Message:
    D:\workspace\source\test-gulp-babel\index.error.js: Unexpected token (2:0)
  1 | var a =
> 2 |
    | ^
[13:20:46] Finished 'babel' after 426 ms
[13:20:46] Starting 'after-babel'...
[13:20:46] Finished 'after-babel' after 5.37 ms

Without logError:
Notice that this doesn't continue on the after-babel task.

[13:22:14] Using gulpfile D:\workspace\source\test-gulp-babel\gulpfile.js
[13:22:14] Starting 'babel'...

events.js:160
      throw er; // Unhandled 'error' event
      ^
SyntaxError: D:\workspace\source\test-gulp-babel\index.error.js: Unexpected token (2:0)
  1 | var a =
> 2 |
    | ^
    at Parser.raise (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:807:15)
    at Parser.unexpected (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2068:16)
    at Parser.parseExprAtom (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:3120:20)
    at Parser.parseExprSubscripts (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2770:21)
    at Parser.parseMaybeUnary (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2748:21)
    at Parser.parseExprOps (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2671:21)
    at Parser.parseMaybeConditional (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2647:21)
    at Parser.parseMaybeAssign (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:2607:21)
    at Parser.parseVar (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:4508:26)
    at Parser.parseVarStatement (D:\workspace\source\gulp-babel\node_modules\babylon\lib\index.js:4324:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-gulp-babel@1.0.0 start: `gulp after-babel`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-gulp-babel@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\tommaso\AppData\Roaming\npm-cache\_logs\2017-10-13T11_22_14_707Z-debug.log

@Lemmmy
Copy link

Lemmmy commented Apr 23, 2018

Any updates on this PR?

@loganfsmyth
Copy link
Member

loganfsmyth commented Sep 3, 2018

I'm not sure having this be part of gulp-babel makes sense. It's a general utility function for gulp streams, so it seems like it would be better in a utility package, if it's not already available.

@loganfsmyth loganfsmyth closed this Sep 3, 2018
@tomsotte
Copy link
Author

tomsotte commented Sep 3, 2018

I see your point, it may be best as an external utility package.
At the time I haven't found one and gulp-sass had this function that was helpful in logging the errors without interrupting the watch.

@loganfsmyth
Copy link
Member

I was probably being overly aggressive, I don't really have an issue with landing this if you want. It will need to be tweaked and rebased for Babel 7 though. err.codeFrame doesn't exist anymore, so it'll literally be just stringifying the err.

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

Successfully merging this pull request may close these issues.

3 participants