oxc-project/oxc · error · OxcDiagnostic

Don't use `process.exit()`

Error message

Don't use `process.exit()`

What it means

Lint diagnostic from unicorn/no-process-exit: process.exit() was called. It terminates immediately without unwinding, skipping pending async work, stdout flushes, and cleanup handlers, which corrupts long-running programs and CLI pipes.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_process_exit.rs:9

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{AstNode, ast_util::is_method_call, context::LintContext, rule::Rule};

fn no_process_exit_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Don't use `process.exit()`")
        .with_help("Throw an error instead.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoProcessExit;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow all usage of `process.exit()`.
    ///
    /// ### Why is this bad?
    ///
    /// `process.exit()` should generally only be used in command-line utilities. In all other
    /// types of applications, the code should throw an error instead.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Throw an error and let the top-level handler decide the exit code
  2. Set process.exitCode and return/resolve normally so pending I/O can flush
  3. Restructure control flow to reach the end of main instead of exiting mid-flight
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_process_exit.rs:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/55efb8df13bc601c. Report an issue: GitHub.