diff options
author | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 23:08:57 +0300 |
---|---|---|
committer | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 23:08:57 +0300 |
commit | 726b81b19251674e149ccfbb1abacbd837fc6db0 (patch) | |
tree | fbdbb227dc01357eb76e8222d76185bc124c5ca6 /node_modules/serialize-error/index.js | |
parent | 34f0890e175698940d49238097579f44e4d78c89 (diff) | |
download | FlashRunner-726b81b19251674e149ccfbb1abacbd837fc6db0.tar.gz FlashRunner-726b81b19251674e149ccfbb1abacbd837fc6db0.tar.zst |
Removed files that should not have been included in git
Diffstat (limited to 'node_modules/serialize-error/index.js')
-rw-r--r-- | node_modules/serialize-error/index.js | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/node_modules/serialize-error/index.js b/node_modules/serialize-error/index.js deleted file mode 100644 index 508c6a2..0000000 --- a/node_modules/serialize-error/index.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -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); - } - } - - 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 too, unless a function is thrown directly. - return `[Function: ${(value.name || 'anonymous')}]`; - } - - return value; -}; - -const deserializeError = value => { - if (value instanceof Error) { - return value; - } - - if (typeof value === 'object' && value !== null && !Array.isArray(value)) { - const newError = new Error(); - destroyCircular({from: value, seen: [], to_: newError}); - return newError; - } - - return new NonError(value); -}; - -module.exports = { - serializeError, - deserializeError -}; |