Skip to content

SuppressedError

In JavaScript, SuppressedError is the native error type that the engine throws when cleanup code fails while another error is already leaving a scope. It extends Error, so it carries a message, a name, and a stack trace, plus two properties of its own: .error holds the cleanup failure, and .suppressed holds the error it displaced. Here, a query fails inside a block, and then closing the connection fails too:

Language: JavaScript Filename: cleanup.mjs
{
  using connection = {
    [Symbol.dispose]() {
      throw new Error("Couldn't close the connection");
    },
  };
  throw new Error("Query failed");
}

Running the file ends with the engine’s SuppressedError instead of either original error:

Language: Shell
$ node cleanup.mjs
SuppressedError: An error was suppressed during disposal

After that line, Node.js prints both original errors under [error] and [suppressed], each with its own stack trace.

When JavaScript Throws SuppressedError

The engine raises it at run time, while it disposes of resources, in these situations:

A single error is never wrapped. When only the block throws, or only one disposer, that error propagates unchanged. Each further failure wraps the previous one, so with three failures, .suppressed holds another SuppressedError, and the original error sits at the end of the chain.

Syntax

Code can also create a SuppressedError directly, passing the newer error first and the displaced one second:

Language: JavaScript Syntax
new SuppressedError(<error>, <suppressed>[, <message>])
Parameter Description
error The value stored as .error, usually the error that cleanup threw. It can be any value.
suppressed The value stored as .suppressed, usually the error that was already propagating. It can be any value.
message An optional description, converted to a string. When it’s omitted, .message is an empty string.

The constructor takes no options object, so a SuppressedError never has a .cause property. It works with or without new and returns a new error either way.

Catching SuppressedError

Say a report writer fails because the disk is full, and closing the file then fails too. The catch block checks the type, rethrows anything else, and reads both errors:

Language: JavaScript
> function openFile(name) {
…   return {
…     [Symbol.dispose]() {
…       throw new Error(`Couldn't close ${name}`);
…     },
…   };
… }
undefined

> try {
…   using report = openFile("report.csv");
…   throw new Error("Disk full");
… } catch (error) {
…   if (!(error instanceof SuppressedError)) throw error;
…   [error.error.message, error.suppressed.message]
… }
[ "Couldn't close report.csv", 'Disk full' ]

The root cause is in .suppressed, so code that logs only error.message reports the generic message and loses both failures. The instanceof check fails for errors from another realm, such as an iframe or a node:vm context, while error.name and Error.isError() still work.

Common Messages

V8 gives every SuppressedError that the engine creates the same message:

Message (V8) Usual Cause Fix
An error was suppressed during disposal A disposer or a DisposableStack callback threw while another error was propagating, or after another disposer threw Fix the cleanup failure in .error, then handle the original error in .suppressed

Firefox and Safari Technology Preview word it differently:

V8 Firefox (SpiderMonkey) Safari (JavaScriptCore)
An error was suppressed during disposal An error is suppressed because another error happened while disposing an object No message, so the console shows only SuppressedError

No engine’s message names the actual failure, so the fix starts with logging error.suppressed and error.error.

A developer diagnoses warning cards using a machine labelled TRY, CATCH and FINALLY.

Course

JavaScript Error Handling in Depth for Pythonistas

Port a food bank's all-or-nothing donation import from Python to JavaScript, and learn to define error classes, chain errors with cause, report many errors at once, and use a debugger.

intermediate js py

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026