{"record":{"id":"b3f85b4b8fd82187","repo":"winstonjs/winston","slug":"winston-exitonerror-cannot-be-true-with-no-reject","errorCode":null,"errorMessage":"winston: exitOnError cannot be true with no rejection handlers.","messagePattern":"winston: exitOnError cannot be true with no rejection handlers\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/winston/rejection-handler.js","lineNumber":179,"sourceCode":"   * Logs all relevant information around the `err` and exits the current\n   * process.\n   * @param {Error} err - Error to handle\n   * @returns {mixed} - TODO: add return description.\n   * @private\n   */\n  _unhandledRejection(err) {\n    const info = this.getAllInfo(err);\n    const handlers = this._getRejectionHandlers();\n    // Calculate if we should exit on this error\n    let doExit =\n      typeof this.logger.exitOnError === 'function'\n        ? this.logger.exitOnError(err)\n        : this.logger.exitOnError;\n    let timeout;\n\n    if (!handlers.length && doExit) {\n      // eslint-disable-next-line no-console\n      console.warn('winston: exitOnError cannot be true with no rejection handlers.');\n      // eslint-disable-next-line no-console\n      console.warn('winston: not exiting process.');\n      doExit = false;\n    }\n\n    function gracefulExit() {\n      debug('doExit', doExit);\n      debug('process._exiting', process._exiting);\n\n      if (doExit && !process._exiting) {\n        // Remark: Currently ignoring any rejections from transports when\n        // catching unhandled rejections.\n        if (timeout) {\n          clearTimeout(timeout);\n        }\n        // eslint-disable-next-line no-process-exit\n        process.exit(1);\n      }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/rejection-handler.js#L161-L197","documentation":"winston's RejectionHandler catches unhandled promise rejections. When there are no rejection-handler transports registered and logger.exitOnError is true, winston warns that exiting on error is impossible because nothing would consume/log the rejection, then overrides doExit to false so the process keeps running.","triggerScenarios":"An unhandled promise rejection occurs while logger.exitOnError (or exitOnError callback returns true) but logger.rejections handledBy / the handler has an empty transports list — i.e. rejections are being handled by the handler but no rejection transports were added.","commonSituations":"Enabling logger.exceptions.handle() but forgetting logger.rejections.handle(transport); misconfiguring a logger where the rejection handler exists (e.g. rejections: true in createLogger) with no transports; assuming exitOnError guarantees process exit on rejections.","solutions":["Add at least one rejection handler transport: logger.rejections.handle(new winston.transports.File({ filename: 'rejections.log' })).","Set exitOnError to false (or an appropriate callback) if you intentionally do not want the process to exit on rejections.","Verify the rejection handler's transports array is populated (console-print logger.rejections) before relying on exit behavior."],"exampleFix":"// before\nconst logger = winston.createLogger({ exitOnError: true, rejections: true, transports: [] });\n// after\nconst logger = winston.createLogger({\n  exitOnError: true,\n  rejections: { handledBy: [new winston.transports.File({ filename: 'rejections.log' })] }\n});","handlingStrategy":"validation","validationCode":"// Validate rejection transports before relying on exitOnError\nif (logger.exitOnError === true && (!logger.rejections || logger.rejections.transports.length === 0)) {\n  throw new Error('exitOnError=true requires at least one rejection handler transport');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair exceptions.handle(...) with rejections.handle(...) including at least one transport.","Add a rejection transport (Console or File) to every logger that sets exitOnError true.","Test unhandled rejection behavior in staging, not just uncaught exceptions."],"tags":["winston","unhandled-rejection","configuration","process-exit"],"backgroundTag":"unhandled-promise-rejection","analyzedSha":"ff0b79de8562bb322c390fbc82fe71c11f373428","analyzedAt":"2026-08-31T13:33:44.585Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}