Skip to content
← All rules
ErrorsError handling

errors/no-lossy-error-wrapping

When a catch handler throws a replacement error, preserve the original failure with a structured cause rather than discarding it.

causewrappingexceptions
TypeScript
try { await load(); } catch { throw new Error("Load failed"); }
Finding

Disallow replacement errors that lose the original cause.

Setup

Install the package, register its plugin factory, then enable the rule.

Install the package

pnpm add -D @scruple/errors

Register the plugin

In scruple.config.ts, register the factory under the errors namespace used by the rule ID.

import { errors } from "@scruple/errors";

plugins: {
  "errors": errors(),
},

Enable the rule

"errors/no-lossy-error-wrapping": "warn"
Package
@scruple/errors
Default threshold
Plugin default
Minimum confidence
Plugin default

Released under the MIT License.