diff --git a/CHANGES.md b/CHANGES.md index c96405a..bdf1feb 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/gulp-prettyerror.js b/gulp-prettyerror.js index 70994c8..058ec35 100755 --- a/gulp-prettyerror.js +++ b/gulp-prettyerror.js @@ -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){ @@ -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 diff --git a/package.json b/package.json old mode 100644 new mode 100755 index cdb80f0..a219147 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/gulpfile.js b/test/gulpfile.js index 3121b6f..e2a82fc 100755 --- a/test/gulpfile.js +++ b/test/gulpfile.js @@ -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' }))