{"record":{"id":"db9a5df1d876a210","repo":"winstonjs/winston","slug":"winston-exitonerror-cannot-be-true-with-no-except","errorCode":null,"errorMessage":"winston: exitOnError cannot be true with no exception handlers.","messagePattern":"winston: exitOnError cannot be true with no exception handlers\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/winston/exception-handler.js","lineNumber":177,"sourceCode":"  /**\n   * 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  _uncaughtException(err) {\n    const info = this.getAllInfo(err);\n    const handlers = this._getExceptionHandlers();\n    // Calculate if we should exit on this error\n    let doExit = 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 exception 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 exceptions from transports when\n        // catching uncaught exceptions.\n        if (timeout) {\n          clearTimeout(timeout);\n        }\n        // eslint-disable-next-line no-process-exit\n        process.exit(1);\n      }","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/exception-handler.js#L159-L195","documentation":"In exception-handler.js _uncaughtException, when an uncaught exception arrives and there are no exception handlers/transports registered but exitOnError resolves to true, winston warns 'exitOnError cannot be true with no exception handlers.' and forces doExit = false instead of killing the process. It alerts you that your exitOnError=true setting has no handlers to run before exit.","triggerScenarios":"logger.exitOnError === true (or exitOnError callback returning true) while logger.exceptions.handlers is empty / no exceptions transports added, and an uncaughtException is caught by winston's handler machinery.","commonSituations":"Setting exitOnError: true in createLogger options but never calling logger.exceptions.handle(...) ; removing exception transports at runtime so handlers.length becomes 0; copying a logger config where exceptions handling was dropped during refactor.","solutions":["Register exception handlers: logger.exceptions.handle(new winston.transports.File({ filename: 'exceptions.log' })).","If no handlers are wanted, set exitOnError: false in createLogger options to silence the warning and keep default Node exit behavior.","If handlers are added dynamically, ensure they exist before an uncaughtException can occur (register at logger creation)."],"exampleFix":"// before\nconst logger = winston.createLogger({ exitOnError: true }); // no exception handlers\n// after\nconst logger = winston.createLogger({ exitOnError: true });\nlogger.exceptions.handle(new winston.transports.File({ filename: 'exceptions.log' }));","handlingStrategy":"validation","validationCode":"if (logger.exitOnError === true && logger.exceptions.handlers.size === 0) {\n  logger.exceptions.handle(new winston.transports.File({ filename: 'exceptions.log' }));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair exitOnError: true with at least one logger.exceptions.handle(...) registration.","Register exception transports at logger creation, not lazily.","Review configs after refactors: exitOnError without exceptionHandlers is a smell."],"tags":["winston","exception-handler","exitonerror","misconfiguration"],"backgroundTag":"exception-handler-misconfigured","analyzedSha":"ff0b79de8562bb322c390fbc82fe71c11f373428","analyzedAt":"2026-08-31T13:33:44.585Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}