@contrast/agent 4.16.1 → 4.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/VERSION +1 -1
- package/bin/linux/contrast-service +0 -0
- package/bin/mac/contrast-service +0 -0
- package/bin/windows/contrast-service.exe +0 -0
- package/esm.mjs +21 -11
- package/lib/assess/policy/propagators.json +4 -0
- package/lib/assess/policy/signatures.json +5 -0
- package/lib/assess/propagators/fastify-static/allowed-path.js +85 -0
- package/lib/cli-rewriter/index.js +1 -1
- package/lib/contrast.js +1 -1
- package/lib/core/rewrite/index.js +2 -2
- package/lib/protect/rules/cmd-injection/cmdinjection-rule.js +1 -1
- package/lib/protect/service.js +2 -0
- package/lib/util/trace-util.js +5 -4
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +49 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/@dabh/diagnostics/README.md +16 -16
- package/node_modules/@dabh/diagnostics/package.json +9 -9
- package/node_modules/async/CHANGELOG.md +13 -0
- package/node_modules/async/all.js +74 -9
- package/node_modules/async/allLimit.js +3 -3
- package/node_modules/async/allSeries.js +3 -3
- package/node_modules/async/any.js +75 -9
- package/node_modules/async/anyLimit.js +3 -3
- package/node_modules/async/anySeries.js +3 -3
- package/node_modules/async/applyEach.js +2 -2
- package/node_modules/async/applyEachSeries.js +2 -2
- package/node_modules/async/asyncify.js +3 -3
- package/node_modules/async/auto.js +81 -15
- package/node_modules/async/autoInject.js +30 -4
- package/node_modules/async/cargo.js +1 -1
- package/node_modules/async/cargoQueue.js +1 -1
- package/node_modules/async/compose.js +1 -1
- package/node_modules/async/concat.js +72 -4
- package/node_modules/async/concatLimit.js +3 -3
- package/node_modules/async/concatSeries.js +2 -2
- package/node_modules/async/detect.js +43 -8
- package/node_modules/async/detectLimit.js +3 -3
- package/node_modules/async/detectSeries.js +3 -3
- package/node_modules/async/dir.js +1 -1
- package/node_modules/async/dist/async.js +1379 -168
- package/node_modules/async/dist/async.min.js +1 -1
- package/node_modules/async/dist/async.mjs +1372 -161
- package/node_modules/async/doDuring.js +3 -3
- package/node_modules/async/doUntil.js +2 -2
- package/node_modules/async/doWhilst.js +3 -3
- package/node_modules/async/during.js +3 -3
- package/node_modules/async/each.js +69 -28
- package/node_modules/async/eachLimit.js +4 -4
- package/node_modules/async/eachOf.js +85 -16
- package/node_modules/async/eachOfLimit.js +3 -3
- package/node_modules/async/eachOfSeries.js +2 -2
- package/node_modules/async/eachSeries.js +2 -2
- package/node_modules/async/ensureAsync.js +2 -2
- package/node_modules/async/every.js +74 -9
- package/node_modules/async/everyLimit.js +3 -3
- package/node_modules/async/everySeries.js +3 -3
- package/node_modules/async/filter.js +49 -9
- package/node_modules/async/filterLimit.js +3 -3
- package/node_modules/async/filterSeries.js +3 -3
- package/node_modules/async/find.js +43 -8
- package/node_modules/async/findLimit.js +3 -3
- package/node_modules/async/findSeries.js +3 -3
- package/node_modules/async/flatMap.js +72 -4
- package/node_modules/async/flatMapLimit.js +3 -3
- package/node_modules/async/flatMapSeries.js +2 -2
- package/node_modules/async/foldl.js +87 -11
- package/node_modules/async/foldr.js +2 -2
- package/node_modules/async/forEach.js +69 -28
- package/node_modules/async/forEachLimit.js +4 -4
- package/node_modules/async/forEachOf.js +85 -16
- package/node_modules/async/forEachOfLimit.js +3 -3
- package/node_modules/async/forEachOfSeries.js +2 -2
- package/node_modules/async/forEachSeries.js +2 -2
- package/node_modules/async/forever.js +4 -4
- package/node_modules/async/groupBy.js +62 -8
- package/node_modules/async/groupByLimit.js +3 -3
- package/node_modules/async/groupBySeries.js +2 -2
- package/node_modules/async/inject.js +87 -11
- package/node_modules/async/internal/applyEach.js +2 -2
- package/node_modules/async/internal/asyncEachOfLimit.js +1 -1
- package/node_modules/async/internal/consoleFunc.js +5 -1
- package/node_modules/async/internal/createTester.js +2 -2
- package/node_modules/async/internal/eachOfLimit.js +6 -6
- package/node_modules/async/internal/filter.js +2 -2
- package/node_modules/async/internal/iterator.js +5 -2
- package/node_modules/async/internal/map.js +1 -1
- package/node_modules/async/internal/parallel.js +3 -3
- package/node_modules/async/internal/queue.js +4 -4
- package/node_modules/async/internal/reject.js +2 -2
- package/node_modules/async/internal/setImmediate.js +6 -2
- package/node_modules/async/internal/wrapAsync.js +1 -1
- package/node_modules/async/log.js +1 -1
- package/node_modules/async/map.js +86 -6
- package/node_modules/async/mapLimit.js +3 -3
- package/node_modules/async/mapSeries.js +3 -3
- package/node_modules/async/mapValues.js +102 -12
- package/node_modules/async/mapValuesLimit.js +4 -4
- package/node_modules/async/mapValuesSeries.js +1 -1
- package/node_modules/async/memoize.js +3 -3
- package/node_modules/async/nextTick.js +3 -3
- package/node_modules/async/package.json +4 -6
- package/node_modules/async/parallel.js +96 -7
- package/node_modules/async/parallelLimit.js +2 -2
- package/node_modules/async/priorityQueue.js +11 -4
- package/node_modules/async/queue.js +4 -4
- package/node_modules/async/race.js +3 -3
- package/node_modules/async/reduce.js +87 -11
- package/node_modules/async/reduceRight.js +2 -2
- package/node_modules/async/reflect.js +2 -2
- package/node_modules/async/reflectAll.js +1 -1
- package/node_modules/async/reject.js +44 -10
- package/node_modules/async/rejectLimit.js +3 -3
- package/node_modules/async/rejectSeries.js +3 -3
- package/node_modules/async/retry.js +2 -2
- package/node_modules/async/retryable.js +4 -4
- package/node_modules/async/select.js +49 -9
- package/node_modules/async/selectLimit.js +3 -3
- package/node_modules/async/selectSeries.js +3 -3
- package/node_modules/async/seq.js +4 -4
- package/node_modules/async/series.js +112 -12
- package/node_modules/async/setImmediate.js +1 -1
- package/node_modules/async/some.js +75 -9
- package/node_modules/async/someLimit.js +3 -3
- package/node_modules/async/someSeries.js +3 -3
- package/node_modules/async/sortBy.js +121 -19
- package/node_modules/async/timeout.js +2 -2
- package/node_modules/async/times.js +1 -1
- package/node_modules/async/timesLimit.js +3 -3
- package/node_modules/async/timesSeries.js +1 -1
- package/node_modules/async/transform.js +111 -19
- package/node_modules/async/tryEach.js +3 -3
- package/node_modules/async/until.js +3 -3
- package/node_modules/async/waterfall.js +4 -4
- package/node_modules/async/whilst.js +3 -3
- package/node_modules/async/wrapSync.js +3 -3
- package/node_modules/color/README.md +9 -0
- package/node_modules/color/index.js +4 -1
- package/node_modules/color/package.json +8 -8
- package/node_modules/color-string/README.md +6 -2
- package/node_modules/color-string/index.js +21 -13
- package/node_modules/color-string/package.json +4 -4
- package/node_modules/colorspace/package.json +5 -5
- package/node_modules/fecha/dist/fecha.min.js +1 -1
- package/node_modules/fecha/dist/fecha.min.js.map +1 -0
- package/node_modules/fecha/lib/fecha.d.ts +2 -2
- package/node_modules/fecha/lib/fecha.js +35 -18
- package/node_modules/fecha/lib/fecha.js.map +1 -0
- package/node_modules/fecha/lib/fecha.umd.js +35 -18
- package/node_modules/fecha/lib/fecha.umd.js.map +1 -0
- package/node_modules/fecha/package.json +9 -10
- package/node_modules/fecha/src/fecha.ts +524 -0
- package/node_modules/logform/.eslintrc +1 -1
- package/node_modules/logform/CHANGELOG.md +24 -0
- package/node_modules/logform/README.md +15 -17
- package/node_modules/logform/browser.js +3 -1
- package/node_modules/logform/cli.js +1 -1
- package/node_modules/logform/colorize.js +2 -2
- package/node_modules/logform/dist/browser.js +8 -2
- package/node_modules/logform/dist/cli.js +2 -2
- package/node_modules/logform/dist/colorize.js +5 -5
- package/node_modules/logform/dist/errors.js +1 -1
- package/node_modules/logform/dist/format.js +9 -5
- package/node_modules/logform/dist/index.js +53 -20
- package/node_modules/logform/dist/json.js +7 -6
- package/node_modules/logform/dist/logstash.js +1 -1
- package/node_modules/logform/dist/pad-levels.js +4 -4
- package/node_modules/logform/dist/printf.js +1 -1
- package/node_modules/logform/dist/simple.js +1 -1
- package/node_modules/logform/dist/splat.js +2 -2
- package/node_modules/logform/dist/uncolorize.js +1 -1
- package/node_modules/logform/errors.js +1 -1
- package/node_modules/logform/index.d.ts +36 -0
- package/node_modules/logform/index.js +19 -20
- package/node_modules/logform/json.js +7 -7
- package/node_modules/logform/logstash.js +1 -1
- package/node_modules/logform/package.json +10 -9
- package/node_modules/logform/simple.js +1 -1
- package/node_modules/logform/uncolorize.js +1 -1
- package/node_modules/safe-stable-stringify/CHANGELOG.md +75 -0
- package/node_modules/safe-stable-stringify/LICENSE +21 -0
- package/node_modules/safe-stable-stringify/esm/package.json +4 -0
- package/node_modules/safe-stable-stringify/esm/wrapper.js +6 -0
- package/node_modules/safe-stable-stringify/index.d.ts +18 -0
- package/node_modules/safe-stable-stringify/index.js +618 -0
- package/node_modules/safe-stable-stringify/package.json +69 -0
- package/node_modules/safe-stable-stringify/readme.md +170 -0
- package/node_modules/safe-stable-stringify/tsconfig.json +22 -0
- package/node_modules/winston/LICENSE +18 -18
- package/node_modules/winston/README.md +1231 -1230
- package/node_modules/winston/dist/winston/common.js +10 -10
- package/node_modules/winston/dist/winston/config/index.js +17 -17
- package/node_modules/winston/dist/winston/container.js +46 -46
- package/node_modules/winston/dist/winston/create-logger.js +28 -24
- package/node_modules/winston/dist/winston/exception-handler.js +49 -49
- package/node_modules/winston/dist/winston/exception-stream.js +27 -27
- package/node_modules/winston/dist/winston/logger.js +152 -138
- package/node_modules/winston/dist/winston/profiler.js +22 -22
- package/node_modules/winston/dist/winston/rejection-handler.js +54 -54
- package/node_modules/winston/dist/winston/tail-file.js +14 -14
- package/node_modules/winston/dist/winston/transports/console.js +31 -31
- package/node_modules/winston/dist/winston/transports/file.js +101 -101
- package/node_modules/winston/dist/winston/transports/http.js +119 -41
- package/node_modules/winston/dist/winston/transports/index.js +17 -17
- package/node_modules/winston/dist/winston/transports/stream.js +24 -24
- package/node_modules/winston/dist/winston.js +91 -97
- package/node_modules/winston/index.d.ts +213 -193
- package/node_modules/winston/lib/winston/common.js +61 -61
- package/node_modules/winston/lib/winston/config/index.d.ts +99 -98
- package/node_modules/winston/lib/winston/config/index.js +35 -35
- package/node_modules/winston/lib/winston/container.js +114 -114
- package/node_modules/winston/lib/winston/create-logger.js +104 -104
- package/node_modules/winston/lib/winston/exception-handler.js +245 -245
- package/node_modules/winston/lib/winston/exception-stream.js +54 -54
- package/node_modules/winston/lib/winston/logger.js +676 -667
- package/node_modules/winston/lib/winston/profiler.js +51 -51
- package/node_modules/winston/lib/winston/rejection-handler.js +251 -251
- package/node_modules/winston/lib/winston/tail-file.js +124 -124
- package/node_modules/winston/lib/winston/transports/console.js +117 -117
- package/node_modules/winston/lib/winston/transports/file.js +695 -695
- package/node_modules/winston/lib/winston/transports/http.js +267 -202
- package/node_modules/winston/lib/winston/transports/index.d.ts +103 -100
- package/node_modules/winston/lib/winston/transports/index.js +56 -56
- package/node_modules/winston/lib/winston/transports/stream.js +63 -63
- package/node_modules/winston/lib/winston.js +176 -182
- package/node_modules/winston/node_modules/winston-transport/.babelrc +3 -0
- package/node_modules/winston/node_modules/winston-transport/.eslintrc +7 -0
- package/node_modules/winston/node_modules/winston-transport/.gitattributes +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -0
- package/node_modules/winston/node_modules/winston-transport/CHANGELOG.md +126 -0
- package/node_modules/winston/node_modules/winston-transport/LICENSE +22 -0
- package/node_modules/winston/node_modules/winston-transport/README.md +50 -0
- package/node_modules/winston/node_modules/winston-transport/dist/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/dist/legacy.js +116 -0
- package/node_modules/winston/node_modules/winston-transport/index.d.ts +39 -0
- package/node_modules/winston/node_modules/winston-transport/index.js +215 -0
- package/node_modules/winston/node_modules/winston-transport/legacy.js +119 -0
- package/node_modules/winston/node_modules/winston-transport/package.json +56 -0
- package/node_modules/winston/package.json +76 -75
- package/package.json +8 -6
- package/node_modules/@dabh/diagnostics/example.png +0 -0
- package/node_modules/color-string/CHANGELOG.md +0 -18
- package/node_modules/colorspace/test.js +0 -14
- package/node_modules/fecha/CHANGELOG.md +0 -67
- package/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston/CHANGELOG.md +0 -560
|
@@ -1,245 +1,245 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* exception-handler.js: Object for handling uncaughtException events.
|
|
3
|
-
*
|
|
4
|
-
* (C) 2010 Charlie Robbins
|
|
5
|
-
* MIT LICENCE
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
const os = require('os');
|
|
11
|
-
const asyncForEach = require('async/forEach');
|
|
12
|
-
const debug = require('@dabh/diagnostics')('winston:exception');
|
|
13
|
-
const once = require('one-time');
|
|
14
|
-
const stackTrace = require('stack-trace');
|
|
15
|
-
const ExceptionStream = require('./exception-stream');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Object for handling uncaughtException events.
|
|
19
|
-
* @type {ExceptionHandler}
|
|
20
|
-
*/
|
|
21
|
-
module.exports = class ExceptionHandler {
|
|
22
|
-
/**
|
|
23
|
-
* TODO: add contructor description
|
|
24
|
-
* @param {!Logger} logger - TODO: add param description
|
|
25
|
-
*/
|
|
26
|
-
constructor(logger) {
|
|
27
|
-
if (!logger) {
|
|
28
|
-
throw new Error('Logger is required to handle exceptions');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.logger = logger;
|
|
32
|
-
this.handlers = new Map();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Handles `uncaughtException` events for the current process by adding any
|
|
37
|
-
* handlers passed in.
|
|
38
|
-
* @returns {undefined}
|
|
39
|
-
*/
|
|
40
|
-
handle(...args) {
|
|
41
|
-
args.forEach(arg => {
|
|
42
|
-
if (Array.isArray(arg)) {
|
|
43
|
-
return arg.forEach(handler => this._addHandler(handler));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this._addHandler(arg);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (!this.catcher) {
|
|
50
|
-
this.catcher = this._uncaughtException.bind(this);
|
|
51
|
-
process.on('uncaughtException', this.catcher);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Removes any handlers to `uncaughtException` events for the current
|
|
57
|
-
* process. This does not modify the state of the `this.handlers` set.
|
|
58
|
-
* @returns {undefined}
|
|
59
|
-
*/
|
|
60
|
-
unhandle() {
|
|
61
|
-
if (this.catcher) {
|
|
62
|
-
process.removeListener('uncaughtException', this.catcher);
|
|
63
|
-
this.catcher = false;
|
|
64
|
-
|
|
65
|
-
Array.from(this.handlers.values())
|
|
66
|
-
.forEach(wrapper => this.logger.unpipe(wrapper));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* TODO: add method description
|
|
72
|
-
* @param {Error} err - Error to get information about.
|
|
73
|
-
* @returns {mixed} - TODO: add return description.
|
|
74
|
-
*/
|
|
75
|
-
getAllInfo(err) {
|
|
76
|
-
let { message } = err;
|
|
77
|
-
if (!message && typeof err === 'string') {
|
|
78
|
-
message = err;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
error: err,
|
|
83
|
-
// TODO (indexzero): how do we configure this?
|
|
84
|
-
level: 'error',
|
|
85
|
-
message: [
|
|
86
|
-
`uncaughtException: ${(message || '(no error message)')}`,
|
|
87
|
-
err.stack || ' No stack trace'
|
|
88
|
-
].join('\n'),
|
|
89
|
-
stack: err.stack,
|
|
90
|
-
exception: true,
|
|
91
|
-
date: new Date().toString(),
|
|
92
|
-
process: this.getProcessInfo(),
|
|
93
|
-
os: this.getOsInfo(),
|
|
94
|
-
trace: this.getTrace(err)
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Gets all relevant process information for the currently running process.
|
|
100
|
-
* @returns {mixed} - TODO: add return description.
|
|
101
|
-
*/
|
|
102
|
-
getProcessInfo() {
|
|
103
|
-
return {
|
|
104
|
-
pid: process.pid,
|
|
105
|
-
uid: process.getuid ? process.getuid() : null,
|
|
106
|
-
gid: process.getgid ? process.getgid() : null,
|
|
107
|
-
cwd: process.cwd(),
|
|
108
|
-
execPath: process.execPath,
|
|
109
|
-
version: process.version,
|
|
110
|
-
argv: process.argv,
|
|
111
|
-
memoryUsage: process.memoryUsage()
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Gets all relevant OS information for the currently running process.
|
|
117
|
-
* @returns {mixed} - TODO: add return description.
|
|
118
|
-
*/
|
|
119
|
-
getOsInfo() {
|
|
120
|
-
return {
|
|
121
|
-
loadavg: os.loadavg(),
|
|
122
|
-
uptime: os.uptime()
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Gets a stack trace for the specified error.
|
|
128
|
-
* @param {mixed} err - TODO: add param description.
|
|
129
|
-
* @returns {mixed} - TODO: add return description.
|
|
130
|
-
*/
|
|
131
|
-
getTrace(err) {
|
|
132
|
-
const trace = err ? stackTrace.parse(err) : stackTrace.get();
|
|
133
|
-
return trace.map(site => {
|
|
134
|
-
return {
|
|
135
|
-
column: site.getColumnNumber(),
|
|
136
|
-
file: site.getFileName(),
|
|
137
|
-
function: site.getFunctionName(),
|
|
138
|
-
line: site.getLineNumber(),
|
|
139
|
-
method: site.getMethodName(),
|
|
140
|
-
native: site.isNative()
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Helper method to add a transport as an exception handler.
|
|
147
|
-
* @param {Transport} handler - The transport to add as an exception handler.
|
|
148
|
-
* @returns {void}
|
|
149
|
-
*/
|
|
150
|
-
_addHandler(handler) {
|
|
151
|
-
if (!this.handlers.has(handler)) {
|
|
152
|
-
handler.handleExceptions = true;
|
|
153
|
-
const wrapper = new ExceptionStream(handler);
|
|
154
|
-
this.handlers.set(handler, wrapper);
|
|
155
|
-
this.logger.pipe(wrapper);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Logs all relevant information around the `err` and exits the current
|
|
161
|
-
* process.
|
|
162
|
-
* @param {Error} err - Error to handle
|
|
163
|
-
* @returns {mixed} - TODO: add return description.
|
|
164
|
-
* @private
|
|
165
|
-
*/
|
|
166
|
-
_uncaughtException(err) {
|
|
167
|
-
const info = this.getAllInfo(err);
|
|
168
|
-
const handlers = this._getExceptionHandlers();
|
|
169
|
-
// Calculate if we should exit on this error
|
|
170
|
-
let doExit = typeof this.logger.exitOnError === 'function'
|
|
171
|
-
? this.logger.exitOnError(err)
|
|
172
|
-
: this.logger.exitOnError;
|
|
173
|
-
let timeout;
|
|
174
|
-
|
|
175
|
-
if (!handlers.length && doExit) {
|
|
176
|
-
// eslint-disable-next-line no-console
|
|
177
|
-
console.warn('winston: exitOnError cannot be true with no exception handlers.');
|
|
178
|
-
// eslint-disable-next-line no-console
|
|
179
|
-
console.warn('winston: not exiting process.');
|
|
180
|
-
doExit = false;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function gracefulExit() {
|
|
184
|
-
debug('doExit', doExit);
|
|
185
|
-
debug('process._exiting', process._exiting);
|
|
186
|
-
|
|
187
|
-
if (doExit && !process._exiting) {
|
|
188
|
-
// Remark: Currently ignoring any exceptions from transports when
|
|
189
|
-
// catching uncaught exceptions.
|
|
190
|
-
if (timeout) {
|
|
191
|
-
clearTimeout(timeout);
|
|
192
|
-
}
|
|
193
|
-
// eslint-disable-next-line no-process-exit
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!handlers || handlers.length === 0) {
|
|
199
|
-
return process.nextTick(gracefulExit);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Log to all transports attempting to listen for when they are completed.
|
|
203
|
-
asyncForEach(handlers, (handler, next) => {
|
|
204
|
-
const done = once(next);
|
|
205
|
-
const transport = handler.transport || handler;
|
|
206
|
-
|
|
207
|
-
// Debug wrapping so that we can inspect what's going on under the covers.
|
|
208
|
-
function onDone(event) {
|
|
209
|
-
return () => {
|
|
210
|
-
debug(event);
|
|
211
|
-
done();
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
transport._ending = true;
|
|
216
|
-
transport.once('finish', onDone('finished'));
|
|
217
|
-
transport.once('error', onDone('error'));
|
|
218
|
-
}, () => doExit && gracefulExit());
|
|
219
|
-
|
|
220
|
-
this.logger.log(info);
|
|
221
|
-
|
|
222
|
-
// If exitOnError is true, then only allow the logging of exceptions to
|
|
223
|
-
// take up to `3000ms`.
|
|
224
|
-
if (doExit) {
|
|
225
|
-
timeout = setTimeout(gracefulExit, 3000);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Returns the list of transports and exceptionHandlers for this instance.
|
|
231
|
-
* @returns {Array} - List of transports and exceptionHandlers for this
|
|
232
|
-
* instance.
|
|
233
|
-
* @private
|
|
234
|
-
*/
|
|
235
|
-
_getExceptionHandlers() {
|
|
236
|
-
// Remark (indexzero): since `logger.transports` returns all of the pipes
|
|
237
|
-
// from the _readableState of the stream we actually get the join of the
|
|
238
|
-
// explicit handlers and the implicit transports with
|
|
239
|
-
// `handleExceptions: true`
|
|
240
|
-
return this.logger.transports.filter(wrap => {
|
|
241
|
-
const transport = wrap.transport || wrap;
|
|
242
|
-
return transport.handleExceptions;
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* exception-handler.js: Object for handling uncaughtException events.
|
|
3
|
+
*
|
|
4
|
+
* (C) 2010 Charlie Robbins
|
|
5
|
+
* MIT LICENCE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const asyncForEach = require('async/forEach');
|
|
12
|
+
const debug = require('@dabh/diagnostics')('winston:exception');
|
|
13
|
+
const once = require('one-time');
|
|
14
|
+
const stackTrace = require('stack-trace');
|
|
15
|
+
const ExceptionStream = require('./exception-stream');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Object for handling uncaughtException events.
|
|
19
|
+
* @type {ExceptionHandler}
|
|
20
|
+
*/
|
|
21
|
+
module.exports = class ExceptionHandler {
|
|
22
|
+
/**
|
|
23
|
+
* TODO: add contructor description
|
|
24
|
+
* @param {!Logger} logger - TODO: add param description
|
|
25
|
+
*/
|
|
26
|
+
constructor(logger) {
|
|
27
|
+
if (!logger) {
|
|
28
|
+
throw new Error('Logger is required to handle exceptions');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.handlers = new Map();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Handles `uncaughtException` events for the current process by adding any
|
|
37
|
+
* handlers passed in.
|
|
38
|
+
* @returns {undefined}
|
|
39
|
+
*/
|
|
40
|
+
handle(...args) {
|
|
41
|
+
args.forEach(arg => {
|
|
42
|
+
if (Array.isArray(arg)) {
|
|
43
|
+
return arg.forEach(handler => this._addHandler(handler));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this._addHandler(arg);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!this.catcher) {
|
|
50
|
+
this.catcher = this._uncaughtException.bind(this);
|
|
51
|
+
process.on('uncaughtException', this.catcher);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Removes any handlers to `uncaughtException` events for the current
|
|
57
|
+
* process. This does not modify the state of the `this.handlers` set.
|
|
58
|
+
* @returns {undefined}
|
|
59
|
+
*/
|
|
60
|
+
unhandle() {
|
|
61
|
+
if (this.catcher) {
|
|
62
|
+
process.removeListener('uncaughtException', this.catcher);
|
|
63
|
+
this.catcher = false;
|
|
64
|
+
|
|
65
|
+
Array.from(this.handlers.values())
|
|
66
|
+
.forEach(wrapper => this.logger.unpipe(wrapper));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* TODO: add method description
|
|
72
|
+
* @param {Error} err - Error to get information about.
|
|
73
|
+
* @returns {mixed} - TODO: add return description.
|
|
74
|
+
*/
|
|
75
|
+
getAllInfo(err) {
|
|
76
|
+
let { message } = err;
|
|
77
|
+
if (!message && typeof err === 'string') {
|
|
78
|
+
message = err;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
error: err,
|
|
83
|
+
// TODO (indexzero): how do we configure this?
|
|
84
|
+
level: 'error',
|
|
85
|
+
message: [
|
|
86
|
+
`uncaughtException: ${(message || '(no error message)')}`,
|
|
87
|
+
err.stack || ' No stack trace'
|
|
88
|
+
].join('\n'),
|
|
89
|
+
stack: err.stack,
|
|
90
|
+
exception: true,
|
|
91
|
+
date: new Date().toString(),
|
|
92
|
+
process: this.getProcessInfo(),
|
|
93
|
+
os: this.getOsInfo(),
|
|
94
|
+
trace: this.getTrace(err)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Gets all relevant process information for the currently running process.
|
|
100
|
+
* @returns {mixed} - TODO: add return description.
|
|
101
|
+
*/
|
|
102
|
+
getProcessInfo() {
|
|
103
|
+
return {
|
|
104
|
+
pid: process.pid,
|
|
105
|
+
uid: process.getuid ? process.getuid() : null,
|
|
106
|
+
gid: process.getgid ? process.getgid() : null,
|
|
107
|
+
cwd: process.cwd(),
|
|
108
|
+
execPath: process.execPath,
|
|
109
|
+
version: process.version,
|
|
110
|
+
argv: process.argv,
|
|
111
|
+
memoryUsage: process.memoryUsage()
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gets all relevant OS information for the currently running process.
|
|
117
|
+
* @returns {mixed} - TODO: add return description.
|
|
118
|
+
*/
|
|
119
|
+
getOsInfo() {
|
|
120
|
+
return {
|
|
121
|
+
loadavg: os.loadavg(),
|
|
122
|
+
uptime: os.uptime()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Gets a stack trace for the specified error.
|
|
128
|
+
* @param {mixed} err - TODO: add param description.
|
|
129
|
+
* @returns {mixed} - TODO: add return description.
|
|
130
|
+
*/
|
|
131
|
+
getTrace(err) {
|
|
132
|
+
const trace = err ? stackTrace.parse(err) : stackTrace.get();
|
|
133
|
+
return trace.map(site => {
|
|
134
|
+
return {
|
|
135
|
+
column: site.getColumnNumber(),
|
|
136
|
+
file: site.getFileName(),
|
|
137
|
+
function: site.getFunctionName(),
|
|
138
|
+
line: site.getLineNumber(),
|
|
139
|
+
method: site.getMethodName(),
|
|
140
|
+
native: site.isNative()
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Helper method to add a transport as an exception handler.
|
|
147
|
+
* @param {Transport} handler - The transport to add as an exception handler.
|
|
148
|
+
* @returns {void}
|
|
149
|
+
*/
|
|
150
|
+
_addHandler(handler) {
|
|
151
|
+
if (!this.handlers.has(handler)) {
|
|
152
|
+
handler.handleExceptions = true;
|
|
153
|
+
const wrapper = new ExceptionStream(handler);
|
|
154
|
+
this.handlers.set(handler, wrapper);
|
|
155
|
+
this.logger.pipe(wrapper);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Logs all relevant information around the `err` and exits the current
|
|
161
|
+
* process.
|
|
162
|
+
* @param {Error} err - Error to handle
|
|
163
|
+
* @returns {mixed} - TODO: add return description.
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
_uncaughtException(err) {
|
|
167
|
+
const info = this.getAllInfo(err);
|
|
168
|
+
const handlers = this._getExceptionHandlers();
|
|
169
|
+
// Calculate if we should exit on this error
|
|
170
|
+
let doExit = typeof this.logger.exitOnError === 'function'
|
|
171
|
+
? this.logger.exitOnError(err)
|
|
172
|
+
: this.logger.exitOnError;
|
|
173
|
+
let timeout;
|
|
174
|
+
|
|
175
|
+
if (!handlers.length && doExit) {
|
|
176
|
+
// eslint-disable-next-line no-console
|
|
177
|
+
console.warn('winston: exitOnError cannot be true with no exception handlers.');
|
|
178
|
+
// eslint-disable-next-line no-console
|
|
179
|
+
console.warn('winston: not exiting process.');
|
|
180
|
+
doExit = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function gracefulExit() {
|
|
184
|
+
debug('doExit', doExit);
|
|
185
|
+
debug('process._exiting', process._exiting);
|
|
186
|
+
|
|
187
|
+
if (doExit && !process._exiting) {
|
|
188
|
+
// Remark: Currently ignoring any exceptions from transports when
|
|
189
|
+
// catching uncaught exceptions.
|
|
190
|
+
if (timeout) {
|
|
191
|
+
clearTimeout(timeout);
|
|
192
|
+
}
|
|
193
|
+
// eslint-disable-next-line no-process-exit
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!handlers || handlers.length === 0) {
|
|
199
|
+
return process.nextTick(gracefulExit);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Log to all transports attempting to listen for when they are completed.
|
|
203
|
+
asyncForEach(handlers, (handler, next) => {
|
|
204
|
+
const done = once(next);
|
|
205
|
+
const transport = handler.transport || handler;
|
|
206
|
+
|
|
207
|
+
// Debug wrapping so that we can inspect what's going on under the covers.
|
|
208
|
+
function onDone(event) {
|
|
209
|
+
return () => {
|
|
210
|
+
debug(event);
|
|
211
|
+
done();
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
transport._ending = true;
|
|
216
|
+
transport.once('finish', onDone('finished'));
|
|
217
|
+
transport.once('error', onDone('error'));
|
|
218
|
+
}, () => doExit && gracefulExit());
|
|
219
|
+
|
|
220
|
+
this.logger.log(info);
|
|
221
|
+
|
|
222
|
+
// If exitOnError is true, then only allow the logging of exceptions to
|
|
223
|
+
// take up to `3000ms`.
|
|
224
|
+
if (doExit) {
|
|
225
|
+
timeout = setTimeout(gracefulExit, 3000);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Returns the list of transports and exceptionHandlers for this instance.
|
|
231
|
+
* @returns {Array} - List of transports and exceptionHandlers for this
|
|
232
|
+
* instance.
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
_getExceptionHandlers() {
|
|
236
|
+
// Remark (indexzero): since `logger.transports` returns all of the pipes
|
|
237
|
+
// from the _readableState of the stream we actually get the join of the
|
|
238
|
+
// explicit handlers and the implicit transports with
|
|
239
|
+
// `handleExceptions: true`
|
|
240
|
+
return this.logger.transports.filter(wrap => {
|
|
241
|
+
const transport = wrap.transport || wrap;
|
|
242
|
+
return transport.handleExceptions;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* exception-stream.js: TODO: add file header handler.
|
|
3
|
-
*
|
|
4
|
-
* (C) 2010 Charlie Robbins
|
|
5
|
-
* MIT LICENCE
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
const { Writable } = require('readable-stream');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* TODO: add class description.
|
|
14
|
-
* @type {ExceptionStream}
|
|
15
|
-
* @extends {Writable}
|
|
16
|
-
*/
|
|
17
|
-
module.exports = class ExceptionStream extends Writable {
|
|
18
|
-
/**
|
|
19
|
-
* Constructor function for the ExceptionStream responsible for wrapping a
|
|
20
|
-
* TransportStream; only allowing writes of `info` objects with
|
|
21
|
-
* `info.exception` set to true.
|
|
22
|
-
* @param {!TransportStream} transport - Stream to filter to exceptions
|
|
23
|
-
*/
|
|
24
|
-
constructor(transport) {
|
|
25
|
-
super({ objectMode: true });
|
|
26
|
-
|
|
27
|
-
if (!transport) {
|
|
28
|
-
throw new Error('ExceptionStream requires a TransportStream instance.');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Remark (indexzero): we set `handleExceptions` here because it's the
|
|
32
|
-
// predicate checked in ExceptionHandler.prototype.__getExceptionHandlers
|
|
33
|
-
this.handleExceptions = true;
|
|
34
|
-
this.transport = transport;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Writes the info object to our transport instance if (and only if) the
|
|
39
|
-
* `exception` property is set on the info.
|
|
40
|
-
* @param {mixed} info - TODO: add param description.
|
|
41
|
-
* @param {mixed} enc - TODO: add param description.
|
|
42
|
-
* @param {mixed} callback - TODO: add param description.
|
|
43
|
-
* @returns {mixed} - TODO: add return description.
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
_write(info, enc, callback) {
|
|
47
|
-
if (info.exception) {
|
|
48
|
-
return this.transport.log(info, callback);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
callback();
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* exception-stream.js: TODO: add file header handler.
|
|
3
|
+
*
|
|
4
|
+
* (C) 2010 Charlie Robbins
|
|
5
|
+
* MIT LICENCE
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const { Writable } = require('readable-stream');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TODO: add class description.
|
|
14
|
+
* @type {ExceptionStream}
|
|
15
|
+
* @extends {Writable}
|
|
16
|
+
*/
|
|
17
|
+
module.exports = class ExceptionStream extends Writable {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor function for the ExceptionStream responsible for wrapping a
|
|
20
|
+
* TransportStream; only allowing writes of `info` objects with
|
|
21
|
+
* `info.exception` set to true.
|
|
22
|
+
* @param {!TransportStream} transport - Stream to filter to exceptions
|
|
23
|
+
*/
|
|
24
|
+
constructor(transport) {
|
|
25
|
+
super({ objectMode: true });
|
|
26
|
+
|
|
27
|
+
if (!transport) {
|
|
28
|
+
throw new Error('ExceptionStream requires a TransportStream instance.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Remark (indexzero): we set `handleExceptions` here because it's the
|
|
32
|
+
// predicate checked in ExceptionHandler.prototype.__getExceptionHandlers
|
|
33
|
+
this.handleExceptions = true;
|
|
34
|
+
this.transport = transport;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Writes the info object to our transport instance if (and only if) the
|
|
39
|
+
* `exception` property is set on the info.
|
|
40
|
+
* @param {mixed} info - TODO: add param description.
|
|
41
|
+
* @param {mixed} enc - TODO: add param description.
|
|
42
|
+
* @param {mixed} callback - TODO: add param description.
|
|
43
|
+
* @returns {mixed} - TODO: add return description.
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
_write(info, enc, callback) {
|
|
47
|
+
if (info.exception) {
|
|
48
|
+
return this.transport.log(info, callback);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
callback();
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
};
|