Repository navigation
Expand file tree
/
Copy patherrors.js
More file actions
56 lines (46 loc) · 1.38 KB
/
Copy patherrors.js
File metadata and controls
56 lines (46 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var chalk = require('chalk'),
util = require('util'),
GeminiError = require('../errors/gemini-error');
function handleErrors(error) {
printErrorHeader(error);
if (error instanceof GeminiError) {
handleGeminiError(error);
} else if (error.status === 13) {
//unknow wd error
handleUnknownWdError(error);
} else {
console.error(error.stack || error.message);
}
// exit code
return 1;
}
function handleUncaughtExceptions() {
process.on('uncaughtException', function(error) {
process.exit(handleErrors(error));
});
}
function printErrorHeader(e) {
var message = [chalk.red('Critical error')];
if (e.state) {
message.push(util.format('while running "%s"', e.state.fullName));
}
if (e.browserId) {
message.push(util.format('in %s', chalk.underline(e.browserId)));
if (e.sessionId) {
message.push(util.format('(%s)', chalk.yellow(e.sessionId)));
}
}
console.error(message.join(' ') + ':');
}
function handleGeminiError(error) {
console.error(error.message);
if (error.advice) {
console.error(chalk.green('To fix:'), error.advice);
}
}
function handleUnknownWdError(error) {
console.error(error.cause.value.message);
}
exports.handleErrors = handleErrors;
exports.handleUncaughtExceptions = handleUncaughtExceptions;