Skip to content

Commit

Permalink
Improve error rendering. Now includes line numbers in 'at:' block if …
Browse files Browse the repository at this point in the history
…they are annotated in the error
  • Loading branch information
Munter committed Apr 11, 2015
1 parent 2f7df05 commit 7de2c64
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var request = require('request');

var TapRender = require('tap-render');

var t = TapRender();
var t = new TapRender();

module.exports = function (options) {
options = options || {};
Expand Down Expand Up @@ -131,39 +131,40 @@ module.exports = function (options) {
}
});

ag.on('warn', function (error) {
function handleError(error) {
var report = {
ok: false,
name: '',
name: ('should not have any errors loading ' + (error.relation ? 'relation' : 'asset')),
operator: 'error',
actual: error.message
};

if (error.asset) {
report.at = error.asset.urlOrDescription;
}

errorCount += 1;
if (error.line) {
report.at += ':' + error.line;

t.push(null, report);
});
if (error.column) {
report.at += ':' + error.column;
}
}
}

ag.on('error', function (error) {
var report = {
ok: false,
name: '',
operator: 'error',
actual: error.message
};
if (error.relation) {
report.at = error.relation.toString();
}

if (error.asset) {
report.at = error.asset.urlOrDescription;
if (error.stack) {
report.actual.stack += error.stack;
}

errorCount += 1;

t.push(null, report);
});
}

ag.on('warn', handleError);
ag.on('error', handleError);

t.pipe(process.stdout);
t.begin();
Expand Down Expand Up @@ -202,7 +203,7 @@ module.exports = function (options) {
return httpStatus(url, hrefMap[url]);
}),
20,
function (err, results) {
function (err) {
// console.error('Outgoing link status codes:');
// console.error(_.countBy(results, function (r) { return r; }));

Expand Down

0 comments on commit 7de2c64

Please sign in to comment.