grunt.util.error rendering
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
A colleague (@sp90) and I were adding error output from a terminal tool to a Grunt task, for Grunt to pass on to the user. The task is async and something along the lines of this:
``` js
grunt.registerMultiTask('terminal-task', 'Execute some terminal tool', function() {
var done = this.async();
this.files.forEachAsync(function(file, idx, next) {
grunt.spawn({
cmd: 'sometool',
args: [file]
}, function(err, res) {
if(err !== null) return next(grunt.util.error(err));
//Do something with res
next();
});
}, done);
```
What we were surprised to see was that the error was not rendered by Grunt like `grunt.log.error`, which is what we expected, but rendered like `grunt.log.warn`. I tried to dig through the commit log, but didn't see anything about this being a conscious decision. The closest I found was #1163, but is in my opinion only tangentially related.
The relevant lines are [`lib/util/task.js#L220-L222`](https://github.com/gruntjs/grunt/blob/77155e3f61d213c529a16ea595fc486fdeca28c9/lib/util/task.js#L220-L222) -> [`lib/grunt.js#L136-L138`](https://github.com/gruntjs/grunt/blob/77155e3f61d213c529a16ea595fc486fdeca28c9/lib/grunt.js#L136-L138) -> [`lib/grunt/fail.js#L28-L40`](https://github.com/gruntjs/grunt/blob/77155e3f61d213c529a16ea595fc486fdeca28c9/lib/grunt/fail.js#L28-L40)
What I want to know is:
- is this intended behaviour or legacy?
- Can/should we fix this?
- Is `grunt.util.error` meant to be used like this?
Contributor guide
Research direction
Start with the referenced lines in lib/util/task.js, lib/grunt.js, and lib/grunt/fail.js to trace how grunt.util.error reaches the output renderer. Compare that path with grunt.log.error and grunt.log.warn, then determine whether the observed rendering is intended and whether this API usage should be supported. Done means the behavior and any required change are clearly decided.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100