diff --git a/federation/src/index.ts b/federation/src/index.ts index ad0df6b0f..d2249badb 100644 --- a/federation/src/index.ts +++ b/federation/src/index.ts @@ -28,11 +28,11 @@ async function main() { `GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}/api/${CONFIG.FEDERATION_API}`, ) } - onShutdown(async (reason, details) => { + onShutdown(async (reason, error) => { if (ShutdownReason.SIGINT === reason || ShutdownReason.SIGTERM === reason) { logger.info(`graceful shutdown: ${reason}`) } else { - logger.error(`crash: ${reason} ${details}`) + logger.error(`crash: ${reason}`, error) } }) }) diff --git a/shared/src/helper/BinaryData.ts b/shared/src/helper/BinaryData.ts index d4af1142b..f1d16c4a0 100644 --- a/shared/src/helper/BinaryData.ts +++ b/shared/src/helper/BinaryData.ts @@ -12,18 +12,6 @@ export class BinaryData { private hex: string constructor(input: Buffer | string | undefined) { - if (!input) { - logging.debug('constructor() with undefined input') - } - logging.debug(`constructor() input type: ${typeof input}`) - logging.debug(`constructor() input isBuffer: ${Buffer.isBuffer(input)}`) - if (typeof input === 'string') { - logging.debug(`constructor() input: ${input}`) - } else if (Buffer.isBuffer(input)) { - logging.debug(`constructor() input: ${input.toString('hex')}`) - } else { - logging.debug(`constructor() unexpected input type: ${typeof input}`) - } if (typeof input === 'string') { this.buf = Buffer.from(input, 'hex') this.hex = input @@ -47,8 +35,10 @@ export class BinaryData { } isSame(other: BinaryData): boolean { - logging.debug(`isSame() this: ${this.buf}`) - logging.debug(`isSame() other: ${other.buf}`) + if (other === undefined || !(other instanceof BinaryData) || other.buf === undefined || !Buffer.isBuffer(other.buf)) { + logging.error('other is invalid', other) + return false + } return this.buf.compare(other.buf) === 0 } } diff --git a/shared/src/helper/onShutdown.ts b/shared/src/helper/onShutdown.ts index ff74699d8..c4d046071 100644 --- a/shared/src/helper/onShutdown.ts +++ b/shared/src/helper/onShutdown.ts @@ -10,7 +10,7 @@ export enum ShutdownReason { * Setup graceful shutdown for the process * @param gracefulShutdown will be called if process is terminated */ -export function onShutdown(shutdownHandler: (reason: ShutdownReason, details?: string) => Promise) { +export function onShutdown(shutdownHandler: (reason: ShutdownReason, error?: Error | any) => Promise) { const signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM'] signals.forEach(sig => { process.on(sig, async () => { @@ -19,13 +19,13 @@ export function onShutdown(shutdownHandler: (reason: ShutdownReason, details?: s }) }) - process.on('uncaughtException', async (err, origin) => { - await shutdownHandler(ShutdownReason.UNCAUGHT_EXCEPTION, `${origin}: ${err}`) + process.on('uncaughtException', async (err) => { + await shutdownHandler(ShutdownReason.UNCAUGHT_EXCEPTION, err) process.exit(1) }) - process.on('unhandledRejection', async (reason, promise) => { - await shutdownHandler(ShutdownReason.UNCAUGHT_REJECTION, `${promise}: ${reason}`) + process.on('unhandledRejection', async (err) => { + await shutdownHandler(ShutdownReason.UNCAUGHT_REJECTION, err) process.exit(1) })