Fix dependabot issues
This commit is contained in:
parent
c89d9bd8b0
commit
531c6ba7c8
705 changed files with 53406 additions and 20466 deletions
132
node_modules/serialize-error/index.js
generated
vendored
132
node_modules/serialize-error/index.js
generated
vendored
|
|
@ -1,63 +1,101 @@
|
|||
'use strict';
|
||||
|
||||
// Make a value ready for JSON.stringify() / process.send()
|
||||
module.exports = function (value) {
|
||||
if (typeof value === 'object') {
|
||||
return destroyCircular(value, []);
|
||||
class NonError extends Error {
|
||||
constructor(message) {
|
||||
super(NonError._prepareSuperMessage(message));
|
||||
Object.defineProperty(this, 'name', {
|
||||
value: 'NonError',
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, NonError);
|
||||
}
|
||||
}
|
||||
|
||||
// People sometimes throw things besides Error objects, so...
|
||||
static _prepareSuperMessage(message) {
|
||||
try {
|
||||
return JSON.stringify(message);
|
||||
} catch (_) {
|
||||
return String(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commonProperties = [
|
||||
{property: 'name', enumerable: false},
|
||||
{property: 'message', enumerable: false},
|
||||
{property: 'stack', enumerable: false},
|
||||
{property: 'code', enumerable: true}
|
||||
];
|
||||
|
||||
const destroyCircular = ({from, seen, to_, forceEnumerable}) => {
|
||||
const to = to_ || (Array.isArray(from) ? [] : {});
|
||||
|
||||
seen.push(from);
|
||||
|
||||
for (const [key, value] of Object.entries(from)) {
|
||||
if (typeof value === 'function') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!value || typeof value !== 'object') {
|
||||
to[key] = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!seen.includes(from[key])) {
|
||||
to[key] = destroyCircular({from: from[key], seen: seen.slice(), forceEnumerable});
|
||||
continue;
|
||||
}
|
||||
|
||||
to[key] = '[Circular]';
|
||||
}
|
||||
|
||||
for (const {property, enumerable} of commonProperties) {
|
||||
if (typeof from[property] === 'string') {
|
||||
Object.defineProperty(to, property, {
|
||||
value: from[property],
|
||||
enumerable: forceEnumerable ? true : enumerable,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return to;
|
||||
};
|
||||
|
||||
const serializeError = value => {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return destroyCircular({from: value, seen: [], forceEnumerable: true});
|
||||
}
|
||||
|
||||
// People sometimes throw things besides Error objects…
|
||||
if (typeof value === 'function') {
|
||||
// JSON.stringify discards functions. We do to, unless a function is thrown directly.
|
||||
return '[Function: ' + (value.name || 'anonymous') + ']';
|
||||
// `JSON.stringify()` discards functions. We do too, unless a function is thrown directly.
|
||||
return `[Function: ${(value.name || 'anonymous')}]`;
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
// https://www.npmjs.com/package/destroy-circular
|
||||
function destroyCircular(from, seen) {
|
||||
var to;
|
||||
if (Array.isArray(from)) {
|
||||
to = [];
|
||||
} else {
|
||||
to = {};
|
||||
const deserializeError = value => {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
|
||||
seen.push(from);
|
||||
|
||||
Object.keys(from).forEach(function (key) {
|
||||
var value = from[key];
|
||||
|
||||
if (typeof value === 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!value || typeof value !== 'object') {
|
||||
to[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (seen.indexOf(from[key]) === -1) {
|
||||
to[key] = destroyCircular(from[key], seen.slice(0));
|
||||
return;
|
||||
}
|
||||
|
||||
to[key] = '[Circular]';
|
||||
});
|
||||
|
||||
if (typeof from.name === 'string') {
|
||||
to.name = from.name;
|
||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||
const newError = new Error();
|
||||
destroyCircular({from: value, seen: [], to_: newError});
|
||||
return newError;
|
||||
}
|
||||
|
||||
if (typeof from.message === 'string') {
|
||||
to.message = from.message;
|
||||
}
|
||||
return new NonError(value);
|
||||
};
|
||||
|
||||
if (typeof from.stack === 'string') {
|
||||
to.stack = from.stack;
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
module.exports = {
|
||||
serializeError,
|
||||
deserializeError
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue