有没有办法让gulp传递错误信息/位置?

时间:2014-07-15 14:14:58

标签: gulp gulp-less

我创建的任务较少:

var gulp = require('gulp'),
    less = require('gulp-less');

gulp.task('dktest-less', function () {
    gulp.src('dktest/**/*.less')
        .pipe(less());
});

当我运行它时,我得到:

(dev) c:\work\dev\dkjs>gulp dktest-less
[16:07:46] Using gulpfile c:\work\dev\dkjs\gulpfile.js
[16:07:46] Starting 'dktest-less'...
[16:07:46] Finished 'dktest-less' after 4.22 ms

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Invalid HEX color code
    at error (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:248:17)
    at Object.Parser.parser.parsers.parsers.entities.color (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:966:29)
    at Object.Parser.parser.parsers.parsers.operand (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1984:34)
    at Object.Parser.parser.parsers.parsers.multiplication (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1882:26)

    at Object.Parser.parser.parsers.parsers.addition (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1911:26)
    at Object.Parser.parser.parsers.parsers.expression (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:2006:30)
    at Object.Parser.parser.parsers.parsers.value (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1851:30)
    at Object.Parser.parser.parsers.parsers.rule (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1575:60)
    at Object.Parser.parser.parsers.parsers.primary (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:731:76)
    at Object.Parser.parser.parsers.parsers.block (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1492:51)

这不是很有用(你怎么搜索无效的十六进制值..?..和哪里?)

如果我手动运行lessc,它会给我:

(dev) c:\work\dev\dkjs\dktest>lessc diffview.less
SyntaxError: Invalid HEX color code in c:\work\dev\dkjs\dktest\diffview.less on line 821, column 48:
820
821     .white .beautify .data em.s16 { color: #880s }
822

我需要做些什么才能通过gulp获取这条精彩内容的错误消息?

1 个答案:

答案 0 :(得分:3)

尝试在代码中添加错误处理函数,如下所示:

var gulp = require('gulp'),
    less = require('gulp-less');

gulp.task('dktest-less', function () {
    gulp.src('dktest/**/*.less')
        .pipe(less().on('error', errorHandler));
});

function errorHandler (error) {
  console.log(error.toString());
  this.emit('end');
}