Skip to content

Conversation

@w3nl
Copy link
Contributor

@w3nl w3nl commented Feb 12, 2026

Introduces the exitOnError option to the logger configuration. This allows the logger to exit the process when an error is logged, providing a mechanism to halt execution in critical failure scenarios.

Summary by CodeRabbit

  • New Features

    • Added an exitOnError configuration to the logger to control error-exit behavior; defaults to false for backward compatibility.
  • Tests

    • Updated tests to cover the new option and to verify the default behavior when no logger configuration is provided.

Introduces the `exitOnError` option to the logger configuration.
This allows the logger to exit the process when an error is logged,
providing a mechanism to halt execution in critical failure scenarios.
@w3nl w3nl requested a review from Copilot February 12, 2026 13:00
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Added an exitOnError option to the logger factory API (default false) and passed it through to Winston's createLogger. Updated tests to assert explicit and default exitOnError behavior.

Changes

Cohort / File(s) Summary
Logger Configuration
src/logger.js
Default export signature extended with exitOnError = false; value forwarded into winston.createLogger; JSDoc updated to document options.exitOnError.
Tests
src/__tests__/logger.feature.test.js
Updated test cases to assert exitOnError: true when provided and to expect exitOnError: false when no loggers/options supplied.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I tweaked a little switch today,
Exit or stay — you choose the way.
Logs whisper softly, clear and bright,
Errors handled, day or night.
Hopping off with a thankful bite 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Adds option to exit process on logger error' directly and clearly summarizes the main change in the changeset—adding an exitOnError option to the logger factory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature-exit-on-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an exitOnError option to the logger factory so callers can control Winston’s exitOnError behavior via this library’s createLogger wrapper.

Changes:

  • Documented a new options.exitOnError parameter in the createLogger JSDoc.
  • Added exitOnError to the createLogger options destructuring with a default value.
  • Passed exitOnError through to winston.createLogger(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/logger.js`:
- Around line 43-49: The logger config passes exitOnError to
winston.createLogger but you manually handle exceptions with
process.on('uncaughtException'), so either remove the exitOnError option from
the logger construction or enable Winston's exception handling instead; to fix,
update the winston.createLogger call (symbol: logger) by deleting the
exitOnError property if you want manual handling, or replace manual handling by
configuring a transport with handleExceptions: true or using exceptionHandlers
in the winston setup and remove the process.on('uncaughtException', ...) handler
accordingly.

Comment on lines 43 to 49
const logger = winston.createLogger({
level,
levels,
defaultMeta: meta,
transports: winstonLoggers
transports: winstonLoggers,
exitOnError
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

winston 3 exitOnError option behavior

💡 Result:

In winston v3, exitOnError controls whether the Node.js process should exit after winston logs an uncaughtException (i.e., when you’ve enabled exception handling via handleExceptions: true on a transport or via exceptionHandlers). By default, winston will exit after logging the uncaught exception. [1][2]

You can change this behavior:

  • Never exit after an uncaught exception log:

    const logger = winston.createLogger({ exitOnError: false });
    // or later:
    logger.exitOnError = false;

    [1][2]

  • Conditional exit (function form): exitOnError(err) can decide per error whether to exit. Example shown in docs:

    function ignoreEpipe(err) {
      return err.code !== 'EPIPE';
    }
    const logger = winston.createLogger({ exitOnError: ignoreEpipe });

    (In this example, it won’t exit for EPIPE, but will exit for other errors.) [1][2]

Note: exitOnError is specifically documented in the context of uncaught exception handling, not normal logger.error(...) calls. [1][2]

Sources: [1] [2]


🏁 Script executed:

# Find and examine the logger.js file to understand context
find . -name "logger.js" -type f

Repository: trojs/logger

Length of output: 157


🏁 Script executed:

# Examine the main logger.js file to understand the full context
cat -n ./src/logger.js

Repository: trojs/logger

Length of output: 4957


Remove unused exitOnError parameter or configure Winston exception handling.

The exitOnError option only takes effect when Winston is configured to handle uncaught exceptions (via handleExceptions: true on a transport or exceptionHandlers). This code manually handles exceptions with process.on('uncaughtException', ...) instead, making exitOnError ineffective. Either remove the parameter or switch to Winston's built-in exception handling if that's the intent.

🤖 Prompt for AI Agents
In `@src/logger.js` around lines 43 - 49, The logger config passes exitOnError to
winston.createLogger but you manually handle exceptions with
process.on('uncaughtException'), so either remove the exitOnError option from
the logger construction or enable Winston's exception handling instead; to fix,
update the winston.createLogger call (symbol: logger) by deleting the
exitOnError property if you want manual handling, or replace manual handling by
configuring a transport with handleExceptions: true or using exceptionHandlers
in the winston setup and remove the process.on('uncaughtException', ...) handler
accordingly.

Corrects the default `exitOnError` value for the logger.

Ensures the logger does not exit on error by default, allowing for more flexible error handling.
@w3nl w3nl merged commit 6a3b449 into main Feb 12, 2026
11 checks passed
@trojs trojs deleted a comment from Copilot AI Feb 12, 2026
@trojs trojs deleted a comment from Copilot AI Feb 12, 2026
@trojs trojs deleted a comment from Copilot AI Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants