Skip to content

Commit 7e13552

Browse files
committed
Merge pull request #371 from sindresorhus/internal-error
Use AvaError for internal errors
2 parents 8346d35 + ac468d1 commit 7e13552

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var figures = require('figures');
99
var globby = require('globby');
1010
var chalk = require('chalk');
1111
var resolveCwd = require('resolve-cwd');
12+
var AvaError = require('./lib/ava-error');
1213
var fork = require('./lib/fork');
1314
var formatter = require('./lib/enhance-assert').formatter();
1415

@@ -138,7 +139,7 @@ Api.prototype.run = function () {
138139
})
139140
.then(function (files) {
140141
if (files.length === 0) {
141-
return Promise.reject(new Error('Couldn\'t find any files to test'));
142+
return Promise.reject(new AvaError('Couldn\'t find any files to test'));
142143
}
143144

144145
self.fileCount = files.length;

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ api.run()
103103
logger.exit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0);
104104
})
105105
.catch(function (err) {
106-
if (err.name === 'Error') {
106+
if (err.name === 'AvaError') {
107107
console.log(' ' + chalk.red(figures.cross) + ' ' + err.message);
108108
} else {
109109
console.error(err.stack);

lib/ava-error.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
function AvaError(message) {
4+
if (!(this instanceof AvaError)) {
5+
return new AvaError(message);
6+
}
7+
8+
this.message = message;
9+
this.name = 'AvaError';
10+
}
11+
12+
module.exports = AvaError;

lib/fork.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var path = require('path');
44
var objectAssign = require('object-assign');
55
var Promise = require('bluebird');
66
var debug = require('debug')('ava');
7+
var AvaError = require('./ava-error');
78
var send = require('./send');
89

910
module.exports = function (file, opts) {
@@ -29,13 +30,13 @@ module.exports = function (file, opts) {
2930

3031
ps.on('exit', function (code) {
3132
if (code > 0 && code !== 143) {
32-
return reject(new Error(relFile + ' exited with a non-zero exit code: ' + code));
33+
return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
3334
}
3435

3536
if (testResults) {
3637
resolve(testResults);
3738
} else {
38-
reject(new Error('Test results were not received from ' + relFile));
39+
reject(new AvaError('Test results were not received from ' + relFile));
3940
}
4041
});
4142

@@ -48,7 +49,7 @@ module.exports = function (file, opts) {
4849
message += ', make sure to import "ava" at the top of your test file';
4950
}
5051

51-
reject(new Error(message));
52+
reject(new AvaError(message));
5253
});
5354
});
5455

0 commit comments

Comments
 (0)