/** * Destroys this manager and all its shards. * @private */ destroy() { if (this.destroyed) return; this.debug(`Manager was destroyed. Called by:\n${new Error('MANAGER_DESTROYED').stack}`); this.destroyed = true; this.shardQueue.clear(); for (const shard of this.shards.values()) shard.destroy({ closeCode: 1000, reset: true, emit: false, log: false }); }
// istanbul ignore next function getLocalStack(startIdx, maxLines) { // from the call stack, we take up to maximum lines, // starting with specified line index: startIdx = startIdx || 0; const endIdx = maxLines > 0 ? startIdx + maxLines : undefined; return new Error().stack .split(`\n`) .filter(line => line.match(/\(.+\)/)) .slice(startIdx, endIdx) .join(`\n`); }
function logSeriousError(error: Error, when: string, nextSteps?: string) { // tslint:disable-next-line no-console console.error( `A ${chalk.bold('serious error')} occurred when ${chalk.bold(when)}. ${ nextSteps ? nextSteps + ' ' : '' }Error details:\n\n${error.stack}\n`, ); }
/** * Fatal Error. Error code is `"EFATAL"`. * @class FatalError * @constructor * @param {String|Error} data Error object or message */ constructor(data) { const error = (typeof data === 'string') ? null : data; const message = error ? error.message : data; super('EFATAL', message); if (error) this.stack = error.stack; }
test('stack is omitted if it is not set on err', t => { t.plan(2) var err = new Error('myerror') delete err.stack var instance = pino(sink(function (chunk, enc, cb) { t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()') delete chunk.time t.equal(chunk.hasOwnProperty('stack'), false) cb() })) instance.level = name instance[name](err) })
/** * Makes a plain error info object from an Error. * @param {Error} err Error to get info from * @returns {Object} * @private */ static makePlainError(err) { return { name: err.name, message: err.message, stack: err.stack, }; }
_wrapMessenger() { for (const methodName of [ 'broadcast', 'sendTo', 'sendToApp', 'sendToAgent', 'sendRandom' ]) { wrapMethod(methodName, this.messenger, this.coreLogger); } function wrapMethod(methodName, messenger, logger) { const originMethod = messenger[methodName]; messenger[methodName] = function() { const stack = new Error().stack.split('\n').slice(1).join('\n'); logger.warn('agent can\'t call %s before server started\n%s', methodName, stack); originMethod.apply(this, arguments); }; messenger.prependOnceListener('egg-ready', () => { messenger[methodName] = originMethod; }); } }
function cachedError(xs) { if (originCache.has(xs)) return originCache.get(xs) const x = Error.stackTraceLimit Error.stackTraceLimit = 4 originCache.set(xs, new Error().stack) Error.stackTraceLimit = x return originCache.get(xs) }
function query(query, connection, xs, args) { query.origin = options.debug ? new Error().stack : cachedError(xs) query.dynamic = query.dynamic || options.no_prepare if (!query.raw && (!Array.isArray(xs) || !Array.isArray(xs.raw))) return nested(xs, args) const promise = new Promise((resolve, reject) => { query.resolve = resolve query.reject = reject ended !== null ? reject(errors.connection('CONNECTION_ENDED', options)) : ready ? send(connection, query, xs, args) : fetchArrayTypes(connection).then(() => send(connection, query, xs, args)).catch(reject) }) addMethods(promise, query) return promise }
app.get('/throw-unhandledRejection-obj', function* () { this.body = 'foo'; new Promise((resolve, reject) => { const err = { name: 'TypeError', message: 'foo reject obj error', stack: new Error().stack, toString() { return this.name + ': ' + this.message; }, }; reject(err); }); });
// in the end of a file function onlyForApps(expectedPlatform) { const stack = new Error().stack || ''; const re = /Appium.(\w+)/g; const caller = stack.split('\n')[2].trim(); const m = re.exec(caller); if (!m) { throw new Error(`Invalid caller ${caller}`); } const callerName = m[1] || m[2]; if (!expectedPlatform) { if (!this.platform) { throw new Error(`${callerName} method can be used only with apps`); } } else if (this.platform !== expectedPlatform.toLowerCase()) { throw new Error(`${callerName} method can be used only with ${expectedPlatform} apps`); } }
process.on('uncaughtException', function (err) { console.error(err.stack); });
/** * @event unexpected * @param {string} event - unhandled event name. * @param {string|Error} e - unhandled error. * @private */ static unexpected(event, e) { // If you should ever get here, your app is definitely broken, and you need to fix // your event handler to prevent unhandled errors during event notifications. // // Console output is suppressed when running tests, to avoid polluting test output // with error messages that are intentional and of no value to the test. /* istanbul ignore if */ if (!npm.main.suppressErrors) { const stack = e instanceof Error ? e.stack : new Error().stack; ColorConsole.error(`Unexpected error in '${event}' event handler.\n${stack}\n`); } }
client.on('error', m => console.log('debug', new Error(m).stack));