question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement a better error handler

See original GitHub issue

I wanted to make a gulp watch task, but every time it stopped when an error were found. Since I’ve searched but found no real workaround, the only solution I found was to handle the error like gulp-sass does. It does not interrupt the watch and just report it on the console.

Solution source: https://github.com/dlmanning/gulp-sass/blob/master/index.js#L178

An easy implementation for whoever has problem with it is:

const babel = require('gulp-babel');

babel.logError = function logError(error) {
	gutil.log(error.toString(), '\n\b', error.codeFrame);
	this.emit('end');
};

// how to use
babel({...})
.on('error', babel.logError)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
tomsottecommented, Jan 27, 2018

It is in fact what I’m proposing, a nifty addition that does not change in any way the current implementation. It just simplifies and reduce code for the developer who just need to log errors while on watch.

1reaction
thenamankumarcommented, Aug 27, 2017

@tomsotte I guess giving the user, chance to work around error event is better than just logging and not throwing an error.

User may need to do something when error event is fired. I am also doing it the same way you are while working with watchers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement complete error handling? - Codegrip
Error handling is when your software is capable to counter or confiscate errors that may have been brought on by a programmer mistake...
Read more >
Better Error Handling In NodeJS With Error Classes
This article is for JavaScript and NodeJS developers who want to improve error-handling in their applications.
Read more >
Best Practices for Node.js Error-handling - Toptal
This article will introduce you to error-handling in Node.js and demonstrate ... Using Node.js built-in Error object is a good practice because it...
Read more >
koa-better-error-handler - npm
A better error-handler for Lad and Koa. Makes `ctx.throw` awesome (best used with koa-404-handler). Latest version: 10.0.7, last published: ...
Read more >
Error handling - Lisperator.net
The exception system we implement here will fall short in the face of parallelism. Proper support for the parallel copyTree needs some more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found