Layerr is a lightweight, dependency-free error wrapping utility for both Node.js and browser environments, designed to enhance error handling in complex applications. Currently at version 3.0.0, it provides a structured way to chain errors, attach arbitrary contextual information, and rename error types dynamically. Layerr is based on the concepts of `VError` but significantly lighter, stripping away Node.js core utility dependencies to ensure better browser compatibility and smaller bundle sizes. It is written in TypeScript and compiled to JavaScript, making it suitable for modern development workflows. The package maintains an active release cadence, focusing on stability and minimal overhead, differentiating itself by its lean design, ESM-only distribution (since v3), and strong TypeScript support for improved developer experience.
npm install layerrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating and wrapping errors with Layerr, attaching contextual information, and dynamically renaming the error type. It simulates an asynchronous operation that may fail and shows how to catch and re-throw an error using Layerr for enhanced debugging and error reporting.
Update your import statements to use `import { Layerr } from 'layerr'` syntax. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` file extensions).Instead of `error.info.code`, use `Layerr.info(error).code` for reliable access to attached data.
Use `setGlobalName` judiciously, preferably at application startup for a consistent error name, or revert it to `null` if temporary changes are needed: `setGlobalName(null)`.
Change `const { Layerr } = require('layerr')` to `import { Layerr } from 'layerr'`. Ensure your project `package.json` has `"type": "module"` or use `.mjs` file extensions for ESM files.Use the static method `const { code } = Layerr.info(err);` to correctly retrieve attached information from a Layerr instance.No dependency data recorded yet.