-
Notifications
You must be signed in to change notification settings - Fork 96
/
stringify-error.js
84 lines (69 loc) · 1.79 KB
/
stringify-error.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const util = require('util');
const log = require('minilog')('wzrd.in');
const uuid = require('uuid').v1;
const stringify = module.exports = function stringifyError(err) {
const id = uuid();
const internal = [];
const external = [ util.format('\n(logs uuid: %s )\n', id) ];
if (err.stack) {
err.stack.split('\n').forEach(function (l) {
internal.push(l);
});
}
else {
internal.push(err.message || 'unspecified error');
}
if (err.message) {
external.push('Error: "' + err.message + '"');
}
else {
external.push('Error: An unspecified error has occurred.');
external.push('(Yes, I know. How helpful.)');
}
internal.push('');
external.push('');
Object.keys(err).forEach(function (k) {
const v = err[k];
if (typeof v === 'string') {
if (v) {
push(`---${k}---\n${indent(v)}\n`);
}
else {
push(`---${k}---\n (blank string)\n`);
}
}
else {
push(`---${k}---\n${indent(util.format(v))}\n`);
}
function indent(txt) {
return txt.split('\n').map((l) => ' ' + l).join('\n');
}
function push(s) {
internal.push(s);
external.push(s);
}
});
internal.forEach(function(txt) {
txt.split('\n').forEach((l) => {
log.error(id + ' : ' + l);
});
});
external.push('');
return external.join('\n');
};
stringify.hello = '---FLAGRANT SYSTEM ERROR---\n'
stringify.goodbye = [
'',
'This is probably an issue with the package, and not wzrd.in itself.',
'If you feel differently, feel free to file a bug report at:',
'',
' https://github.com/jfhbrook/wzrd.in/issues',
'',
'Include the ENTIRETY of the contents of this message, and the maintainer(s)',
'can try to help you out.',
'',
'Have a nice day!',
'',
''
].join('\n');