# segfault-raub

> Catches SIGSEGV and prints diagnostic information

Latest version **3.2.0** (published 2025-02-21) · MIT, BSD-3-Clause, BSD-2-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install segfault-raub
pnpm add segfault-raub
yarn add segfault-raub
bun add segfault-raub
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2025-02-21 |
| First published | 2019-11-25 |
| Weekly downloads | 0 |
| License | MIT, BSD-3-Clause, BSD-2-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=22.14.0 |
| Dependencies | 1 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 7 |
| Author | Luis Blanco |
| Maintainers | raub |
| Keywords | headers, include, events, utils, c++, addon, bindings, native, napi, gyp |

## Links

- npm: https://www.npmjs.com/package/segfault-raub
- Repository: https://github.com/node-3d/segfault-raub
- Homepage: https://github.com/node-3d/segfault-raub#readme
- Issues: https://github.com/node-3d/segfault-raub/issues
- npm.io page: https://npm.io/package/segfault-raub

## Dependencies (1)

- [addon-tools-raub](https://npm.io/package/addon-tools-raub.md) ^9.3.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.2.0 (latest) — 2025-02-21
- 3.1.0 — 2025-01-07
- 3.0.1 — 2024-10-31
- 3.0.0 — 2024-10-31
- 2.3.0 — 2024-05-30
- 2.2.0 — 2024-05-30
- 2.1.2 — 2023-10-07
- 2.1.0 — 2023-05-08
- 2.0.0 — 2023-01-06
- 1.3.2 — 2022-11-28
- 1.3.1 — 2022-09-25
- 1.3.0 — 2022-09-25
- 1.2.0 — 2021-04-25
- 1.1.3 — 2020-08-29
- 1.1.2 — 2020-04-23
- … 3 more at https://npm.io/package/segfault-raub/versions

## README

# Segfault handler for Node.js

This is a part of [Node3D](https://github.com/node-3d) project.

[![NPM](https://badge.fury.io/js/segfault-raub.svg)](https://badge.fury.io/js/segfault-raub)
[![ESLint](https://github.com/node-3d/segfault-raub/actions/workflows/eslint.yml/badge.svg)](https://github.com/node-3d/segfault-raub/actions/workflows/eslint.yml)
[![Test](https://github.com/node-3d/segfault-raub/actions/workflows/test.yml/badge.svg)](https://github.com/node-3d/segfault-raub/actions/workflows/test.yml)

```
npm i -s segfault-raub
```

This module report debug information on process crash (and some other events).
It doesn't affect the performance while the program is running normally.

The module prints to both
**STDERR** and to the **"segfault.log"** file (if it exists inside **"working directory"**).
If there is no such file, it
**won't be created**, so it is up to you if the log-file is needed.

> Note: this **addon uses N-API**, and therefore is ABI-compatible across different
Node.js versions. Addon binaries are precompiled and **there is no compilation**
step during the `npm i` command.

A zero-setup is available: just require the module and it comes pre-equipped with several
signal listeners enabled by default.

```js
require('segfault-raub');
```

> Note: if your project tree contains multiple versions of this module, the first one imported
will seize `global['segfault-raub']`. The rest of them will only re-export `global['segfault-raub']`
and **WILL NOT** import their own **binaries**.

---

If you want to use a custom location instead of "**segfault.log**", use:

```js
require('segfault-raub').setLogPath("C:/my/log/file.txt");
```

**You must create this file first, it must be there when the crash happens.**

See the [TypeScript declarations](/index.d.ts) with comments.


## Configuring Signals

As listed below, some signals (platform specific) are enabled by default. But they can be
enabled/disabled manually:

Example:

```js
const {
    setSignal,
    EXCEPTION_ACCESS_VIOLATION, SIGSEGV,
    EXCEPTION_BREAKPOINT, SIGTRAP,
} = require('segfault-raub');

setSignal(EXCEPTION_ACCESS_VIOLATION, false);
setSignal(SIGSEGV, false);

setSignal(EXCEPTION_BREAKPOINT, true);
setSignal(SIGTRAP, true);

// This enables capturing every signal on Windows.
setSignal(EXCEPTION_ALL, true);
```

On **Windows**, all the **Unix** signals are `null`, and the opposite is true.
Passing `null` as the first parameter to `setSignal` **has no effect and is safe**.


## Demo Methods

These are be helpful to see how the signals are reported and if the log files are being written properly.

* `causeSegfault` - Causes a memory access violation.
* `causeDivisionInt` - Divides an integer by zero.
* `causeOverflow` - Runs infinite recursion (stack overflow).
* `causeIllegal` - Raises an "illegal instruction" exception.

Example:

```js
const { causeSegfault } = require('segfault-raub');
causeSegfault();
```


## Windows Signals

| Signal                             | Enabled | Description                                        |
| :---                               | :---:   | :---                                               |
| EXCEPTION_ALL                      | no      | All of the below.                                  |
| EXCEPTION_ACCESS_VIOLATION         | yes     | Memory access was denied.                          |
| EXCEPTION_ARRAY_BOUNDS_EXCEEDED    | yes     | Array was accessed with an illegal index.          |
| EXCEPTION_INT_DIVIDE_BY_ZERO       | yes     | Attempt to divide by an integer divisor of 0.      |
| EXCEPTION_ILLEGAL_INSTRUCTION      | yes     | Attempt to execute an illegal instruction.         |
| EXCEPTION_NONCONTINUABLE_EXCEPTION | yes     | Can't continue after an exception.                 |
| EXCEPTION_STACK_OVERFLOW           | yes     | The thread used up its stack.                      |
| EXCEPTION_INVALID_HANDLE           | yes     | An invalid handle was specified.                   |
| EXCEPTION_FLT_DIVIDE_BY_ZERO       | no      | Attempt to divide by a float divisor of 0.f.       |
| EXCEPTION_DATATYPE_MISALIGNMENT    | no      | A datatype misalignment was detected.              |
| EXCEPTION_BREAKPOINT               | no      | A Breakpoint has been reached.                     |
| EXCEPTION_SINGLE_STEP              | no      | Continue single-stepping execution.                |
| EXCEPTION_FLT_DENORMAL_OPERAND     | no      | One of the operands is denormal.                   |
| EXCEPTION_FLT_INEXACT_RESULT       | no      | The result cannot be represented exactly.          |
| EXCEPTION_FLT_INVALID_OPERATION    | no      | Floating-point invalid operation.                  |
| EXCEPTION_FLT_OVERFLOW             | no      | The exponent of operation is too large.            |
| EXCEPTION_FLT_STACK_CHECK          | no      | The Stack gone bad after a float operation.        |
| EXCEPTION_FLT_UNDERFLOW            | no      | The exponent of operation is too low.              |
| EXCEPTION_INT_OVERFLOW             | no      | The result of operation is too large.              |
| EXCEPTION_PRIV_INSTRUCTION         | no      | Operation is not allowed in current mode.          |
| EXCEPTION_IN_PAGE_ERROR            | no      | Can't access a memory page.                        |
| EXCEPTION_INVALID_DISPOSITION      | no      | Invalid disposition returned.                      |
| EXCEPTION_GUARD_PAGE               | no      | Accessing PAGE_GUARD-allocated modifier.           |


## Unix Signals

| Signal     | Handling | Enabled | Description                                        |
| :---       | :---:    | :---:   | :---                                               |
| SIGABRT    |    A     | yes     | Process abort signal.                              |
| SIGFPE     |    A     | yes     | Erroneous arithmetic operation.                    |
| SIGSEGV    |    A     | yes     | Invalid memory reference.                          |
| SIGILL     |    A     | yes     | Illegal instruction.                               |
| SIGBUS     |    A     | yes     | Access to an undefined portion of a memory object. |
| SIGTERM    |    T     | no      | Termination signal.                                |
| SIGINT     |    T     | no      | Terminal interrupt signal.                         |
| SIGALRM    |    T     | no      | Alarm clock.                                       |
| SIGCHLD    |    I     | no      | Child process terminated, stopped, or continued.   |
| SIGCONT    |    C     | no      | Continue executing, if stopped.                    |
| SIGHUP     |    T     | no      | Hangup.                                            |
| SIGKILL    |    T     | no      | Kill (cannot be caught or ignored).                |
| SIGPIPE    |    T     | no      | Write on a pipe with no one to read it.            |
| SIGQUIT    |    A     | no      | Terminal quit signal.                              |
| SIGSTOP    |    S     | no      | Stop executing (cannot be caught or ignored).      |
| SIGTSTP    |    S     | no      | Terminal stop signal.                              |
| SIGTTIN    |    S     | no      | Background process attempting read.                |
| SIGTTOU    |    S     | no      | Background process attempting write.               |
| SIGUSR1    |    T     | no      | User-defined signal 1.                             |
| SIGUSR2    |    T     | no      | User-defined signal 2.                             |
| SIGPROF    |    T     | no      | Profiling timer expired.                           |
| SIGSYS     |    A     | no      | Bad system call.                                   |
| SIGTRAP    |    A     | no      | Trace/breakpoint trap.                             |
| SIGURG     |    I     | no      | High bandwidth data is available at a socket.      |
| SIGVTALRM  |    T     | no      | Virtual timer expired.                             |
| SIGXCPU    |    A     | no      | CPU time limit exceeded.                           |
| SIGXFSZ    |    A     | no      | File size limit exceeded.                          |

* `T` - Abnormal termination of the process.
* `A` - Abnormal termination of the process with additional actions.
* `I` - Ignore the signal.
* `S` - Stop the process.
* `C` - Continue the process, if it is stopped; otherwise, ignore the signal.


## Legal notice

This package is derived from [segfault-handler](https://github.com/ddopson/node-segfault-handler).
The original licensing rules apply, see `LICENSE_node-segfault-handler`.

Also this project uses [callstack walker](https://github.com/JochenKalmbach/StackWalker)
which is licensed under BSD-2 Clause.

The rest of this package (the newly introduced files) is licensed under MIT.

---
_Source: https://npm.io/package/segfault-raub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
