Skip to content

Commit

Permalink
Detailed Error Messages are displayed in case or object is provided #6
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Jan 28, 2017
1 parent 5a42be0 commit 33227a1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.2.0 ###
* Enhancement: Detailed Error Messages are displayed in case `error.cause` or `error.codeFrame` object is provided - suggested by [anweshknayak on GitHub](https://github.com/AndiDittrich/gulp-prettyerror/issues/6)

### 1.1.1 ###
* Bugfix: Error handler doesn't emit the `end` event to terminate the current gulp task - thanks to [haqqi on GitHub](https://github.com/AndiDittrich/gulp-prettyerror/pull/4)

Expand Down
25 changes: 23 additions & 2 deletions gulp-prettyerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ var PrettyError = (function(customErrorFormat){
}else{
// default appearance
return _gplumber(function(error){

// extract values and apply defaults
var plugin = error.plugin || 'unknown';
var rawMessage = error.message || 'unknown error';
var message = error.message || 'unknown error';
var codeFrame = error.codeFrame || null;
var cause = error.cause || null;

// detailed message given ? append it
if (cause.message){
var file = cause.filename || 'unknown file';
var line = cause.line || '0';
var position = cause.position || '0';

// generate detailed error message
message = '[' + file + '] - ' + cause.message + ' (' + line + ':' + position + ')';
}

// log the error message
_gutil.log('|- ' + _gutil.colors.bgRed.bold('Build Error in ' + plugin));
_gutil.log('|- ' + _gutil.colors.bgRed.bold(rawMessage));
_gutil.log('|- ' + _gutil.colors.bgRed.bold(message));

// make sure there is codeFrame in the error object
if (codeFrame){
Expand All @@ -36,6 +48,15 @@ var PrettyError = (function(customErrorFormat){
_gutil.log('|- ' + _gutil.colors.bgRed('>>>'));
_gutil.log('|\n ' + msg + '\n |');
_gutil.log('|- ' + _gutil.colors.bgRed('<<<'));

// stacktrace available ?
}else if (cause.stack){
// add indentation
var stacktrace = cause.stack.replace(/^(\s*)/gm, ' | ');

_gutil.log('|- ' + _gutil.colors.bgRed('>>>'));
_gutil.log('|\n' + stacktrace + '\n |');
_gutil.log('|- ' + _gutil.colors.bgRed('<<<'));
}

// make sure the process is finished
Expand Down
4 changes: 2 additions & 2 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-prettyerror",
"version": "1.1.1",
"version": "1.2.0",
"description": "Display Errors in a pretty way, without breaking watch tasks",
"keywords": [
"gulp",
Expand All @@ -20,7 +20,7 @@
"gulp-prettyerror.js"
],
"main": "./gulp-prettyerror.js",
"author": "Andi Dittrich (http://andidittrich.de)",
"author": "Andi Dittrich (https://andidittrich.de)",
"license": "MIT",
"dependencies": {
"gulp-plumber": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _gulp.task('js', function (){
.pipe(_sourcemaps.init())

// create minified (compressed) version
.pipe(_uglify().on('error', _util.log))
.pipe(_uglify())
.pipe(_rename({
suffix: '.min'
}))
Expand Down

0 comments on commit 33227a1

Please sign in to comment.