Polyfill `error.cause`

Overview

Codecov Node Twitter Medium

Polyfill error.cause.

error.cause is a recent JavaScript feature to wrap errors.

try {
  doSomething()
} catch (cause) {
  throw new Error('message', { cause })
}

Unfortunately, it is not supported in Node <16.9.0, Opera nor Safari <15. This library adds support for it in those environments.

Differences with other polyfills

Unlike error-cause:

  • The package size is small (~50kB vs ~2000kB)
  • Error child types still work
  • Error.stackTraceLimit still works
  • error.stack does not include the polyfill's internal code (in Node.js and Chrome)

Unlike core-js/Babel, this does not require adding core-js as a production dependency (~1000kB).

Install

npm install error-cause-polyfill

This package is an ES module and must be loaded using an import or import() statement, not require().

API

polyfill()

Return value: () => void

Modifies the global error types (Error, TypeError, etc.) so they support error.cause. If error.cause is already supported, this is a noop.

import 'error-cause-polyfill/auto'

try {
  doSomething()
} catch (cause) {
  throw new Error('message', { cause })
}

Or alternatively:

import { polyfill } from 'error-cause-polyfill'

polyfill()

try {
  doSomething()
} catch (cause) {
  throw new Error('message', { cause })
}

This returns a function to undo everything.

import { polyfill } from 'error-cause-polyfill'

const undoPolyfill = polyfill()
undoPolyfill()

getErrors()

Return value: object

Returns an object with each error type (Error, TypeError, etc.) but with error.cause support. If error.cause is already supported, this returns the global error types as is.

Unlike polyfill(), this does not modify the global error types.

import { getErrors } from 'error-cause-polyfill'

const Errors = getErrors()

try {
  doSomething()
} catch (cause) {
  throw new Errors.Error('message', { cause })
}

hasSupport()

Return value: boolean

Returns whether the global error types currently support error.cause.

import { hasSupport, polyfill } from 'error-cause-polyfill'

console.log(hasSupport()) // false
polyfill()
console.log(hasSupport()) // true

Related projects

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with โค๏ธ . The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

You might also like...

Error and Success Handler for Passport.js

Error and Success Handler for Passport.js

passport-handler Developed with โค๏ธ by Swรดth ๐Ÿ”Ž Installation npm i passport-handler --save yarn add passport-handler ๐Ÿ”ฎ Importing import Handler from '

Oct 29, 2022

Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer console in your browser

Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer console in your browser

ColorConsole NPM Package Colorconsole provides an interesting way to display colored info, success, warning and error messages on the developer consol

Sep 19, 2022

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

1kb js library contains development debugging, error monitoring and reporting, user problem localization features

Dec 22, 2022

๐Ÿ’ฃ Error handler for CLI applications ๐Ÿ’ฅ

Error handler for CLI applications. Features ๐Ÿ’ฃ Error type-specific handling ๐Ÿš’ Graceful exit โ›‘๏ธ Normalize invalid errors ๐Ÿ“• Log verbosity: full, shor

Dec 20, 2022

Webpack dev tools to make performance analysis, error investigation and loader development more convenient

Webpack dev tools to make performance analysis, error investigation and loader development more convenient

build-tool-inspector Introduction Webpack dev tools to make performance analysis, error investigation and loader development more convenient. Provide

Nov 17, 2022

VS Code extension that adds a red error squiggle to every word in your code.

VS Code extension that adds a red error squiggle to every word in your code.

Dumbisense Dumbisense is a VS Code extension that adds a red error squiggle to every word in your code, with an interesting error message and dino ima

Sep 3, 2022

GraphErr is an open-source error handling library for GraphQL implementations in Deno. It's a lightweight solution that provides developers with descriptive error messages, reducing ambiguity and improving debugging.

GraphErr is an open-source error handling library for GraphQL implementations in Deno. It's a lightweight solution that provides developers with descriptive error messages, reducing ambiguity and improving debugging.

GraphErr Descriptive GraphQL error handling for Deno/Oak servers. Features Provides additional context to GraphQL's native error messaging for faster

Nov 1, 2022

Getting Dislikes Back For Youtube, cause time is precious to at least not waste on junk.

The OpenDislikeAPI Project Getting Dislikes Back For Youtube(TM), cause time is precious to at least not waste on junk. Inspired by a video by Linus T

Jun 16, 2022

GreenWebhook is a proxy or gateway between two systems that helps reduce your carbon footprint by dynamically routing or delaying traffic so that your workloads run when and where they will cause the lowest amount of carbon emissions.

GreenWebhook is a proxy or gateway between two systems that helps reduce your carbon footprint by dynamically routing or delaying traffic so that your workloads run when and where they will cause the lowest amount of carbon emissions.

๐Ÿ’š Welcome to Green Webhook! ๐Ÿ’š Green Webhook is a proxy or gateway between two systems that intelligently chooses which endpoint to send a webhook ev

Nov 23, 2022

A responsive image polyfill for picture, srcset, sizes, and more

Picturefill A responsive image polyfill. Authors: See Authors.txt License: MIT Picturefill has three versions: Version 1 mimics the Picture element pa

Dec 31, 2022

A JSON polyfill. No longer maintained.

๐Ÿšจ Unmaintained ๐Ÿšจ JSON 3 is **deprecated** and **no longer maintained**. Please don't use it in new projects, and migrate existing projects to use th

Dec 24, 2022

jQuery contextMenu plugin & polyfill

jQuery contextMenu plugin & polyfill $.contextMenu is a management facility for - you guessed it - context menus. It was designed for an application w

Dec 29, 2022

A JavaScript polyfill for the HTML5 placeholder attribute

#Placeholders.js - An HTML5 placeholder attribute polyfill Placeholders.js is a polyfill (or shim, or whatever you like to call it) for the HTML5 plac

Nov 20, 2022

๐ŸŽš HTML5 input range slider element polyfill

rangeslider.js Simple, small and fast jQuery polyfill for the HTML5 input type="range" slider element. Check out the examples. Touchscreen friendly

Jan 8, 2023

A window.fetch JavaScript polyfill.

window.fetch polyfill The fetch() function is a Promise-based mechanism for programmatically making web requests in the browser. This project is a pol

Jan 4, 2023

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Jan 14, 2022

Polyfill to remove click delays on browsers with touch UIs

FastClick FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile

Jan 2, 2023

EventSource polyfill

EventSource polyfill - https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events Installing: You can get the code from npm or

Jan 9, 2023

Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill).

@sanity/client Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill). Requirements Sanity Clien

Nov 29, 2022
Comments
  • Bump decode-uri-component from 0.2.0 to 0.2.2

    Bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(1.3.0)
  • 1.3.0(Nov 7, 2022)

  • 1.2.1(Oct 13, 2022)

  • 1.2.0(Oct 13, 2022)

  • 1.1.0(Aug 16, 2022)

  • 1.0.4(Jun 21, 2022)

  • 1.0.3(Jun 20, 2022)

  • 1.0.2(Jun 20, 2022)

  • 1.0.1(Jun 20, 2022)

    • Refactoring (44af001)
    • Refactoring (b6dd51c)
    • Add test (7cd759d)
    • Add test (cbabe39)
    • Update documentation (570300c)
    • Update README (702ff1c)
    • Add documentation (a14d511)
    • Add types (14a6922)
    • Add comment (caab792)
    • Add comment (cc1e9a6)
    • Allow function options (929dc46)
    • Add comments (12b15e8)
    • Improve tests (bb8a677)
    • Add tests (d269c49)
    • Add comments (426bfe3)
    • Improve tests (dcbb96f)
    • Fix test (79d6319)
    • Add test (95b1b06)
    • Improve test (cdd73cd)
    • Add test (77e32d9)
    • Improve tests (7558fa7)
    • Add tests (4577404)
    • Add test (cb22a26)
    • Add test (d71fb8e)
    • Fix test (c507315)
    • Add tests (1a02b66)
    • Split files (14f83f4)
    • Move file (950c75e)
    • Add tests (5492a6c)
    • Refactoring (88e9d59)
    • Add tests (296eacf)
    • Improve test coverage (253a9be)
    • Improve tests (705bf7a)
    • Refactoring (9237504)
    • Fix comment (6f54944)
    • Improve tests (177252b)
    • Simplify tests (49a00a3)
    • Improve tests (2af9c5e)
    • Improve tests (efecab0)
    • Fix linting (fc90c5f)
    • Upgrade @ehmicky/dev-tasks 1.0.76 -> 1.0.77 (9d8a40c)
    • Fix linting (6205460)
    • Refactoring (e39cf1e)
    • Fix linting (dbf70d5)
    • Split file (d24c1eb)
    • Split files (17b6021)
    • Split file (7fbb357)
    • Split files (7148a5f)
    • Add test (b126136)
    • Fix tests (75aadd0)
    • Fix test (ac9f3b4)
    • Fix test (aae811d)
    • Fix test (3058122)
    • Fix test (b1caec3)
    • Improve test (33db87e)
    • Fix test (e537351)
    • Add test (535ffe1)
    • Add skip() (d6f08e4)
    • Improve tests (20b3986)
    • Improve tests (3baa538)
    • Add tests (0bb75b8)
    • Add test (e8fd0ff)
    • Add test (ea913ee)
    • Add test (ffcfe12)
    • Simplify logic (69bc236)
    • Simplify logic (a6c73f8)
    • Rename test() to hasSupport() (5418b76)
    • Add test (28d438f)
    • Refactoring (c578dbe)
    • Add tests (2f14d2e)
    • Add tests (d2b40a0)
    • Add test (e2dc9b7)
    • Add test (a57bff9)
    • Add tests (372899e)
    • Refactoring (7d66cec)
    • Simplify code (2fcf01b)
    • Move file (d629284)
    • Move files (cce2676)
    • Simplify code (6c37ce1)
    • Simplify code (d2cf82b)
    • Add test (e13487a)
    • Simplify code (202ec60)
    • Improve test (ab3380d)
    • Add test (1fa711d)
    • Add test (3ab004b)
    • Add test (b6426ed)
    • Fix test (4e019d5)
    • Add test (781ee61)
    • Refactoring (38af2d2)
    • Simplify helper (e8eb637)
    • Add test (cde5bf7)
    • Add test (e5a5f70)
    • Add test (870ea80)
    • Add test (1bcbeb5)
    • Add test (9bfa575)
    • Add test (951b510)
    • Add test (dda7efa)
    • Add test (dcc920d)
    • Add test (6e2a51c)
    • Add test (f2f6b48)
    • Add test (e34a4d3)
    • Add test (44c0da3)
    • Add test (7ae6cdb)
    • Add test (12c06e2)
    • Fix bug (c10746c)
    • Add more tests (0dcfad2)
    • Add more tests (5d533f9)
    • Refactoring (68fa11a)
    • Refactoring (503aa83)
    • Add more tests (80b4722)
    • Add test (d8bcc89)
    • Add auto (52d9917)
    • Improve code (34dbd7c)
    • Remove OriginalErrors export (1c58d3f)
    • Refactoring (127ea62)
    • Improve tests (5786965)
    • Start removing OriginalErrors (0743d07)
    • Improve tests (77fdcfc)
    • Refactoring (26bdba4)
    • Remove dead code (379a4dd)
    • Use children errors (0b79183)
    • Add tests (54e1661)
    • Use namespace (9eda24b)
    • Rename variable (1ea2aad)
    • Add tests (ef7f22c)
    • Export originalErrors (bc3c7d2)
    • Refactoring (2cde757)
    • Refactoring (de63c8b)
    • Add more tests (8ec218b)
    • Add polyfill tests (3106cb3)
    • Start real tests (5f6f290)
    • Refactoring (92f28ff)
    • Refactoring (a5ae3b9)
    • Refactoring (be065e9)
    • Refactoring (f9c2beb)
    • Improve asserts (78dff5a)
    • Improve asserts (ef55c31)
    • Improve asserts (b254311)
    • Fix bug (939aa95)
    • Refactor (18ae152)
    • Start adding code (3c9b0e3)
    • Fix linting (9418d36)
    • Fix keywords (cd16861)
    • Initial commit (009741e)
    Source code(tar.gz)
    Source code(zip)
Owner
ehmicky
Node.js back-end developer
ehmicky
Jonathan Parker 6 Nov 23, 2022
Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

null 7 Jan 14, 2022
Polyfill to remove click delays on browsers with touch UIs

FastClick FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile

FT Labs 18.8k Jan 2, 2023
Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill).

@sanity/client Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill). Requirements Sanity Clien

Sanity 23 Nov 29, 2022
PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite.

PouchDB for Deno PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite. Usage import PouchDB from 'https://deno.land/x/[email protected]

Aaron Huggins 19 Aug 2, 2022
Window.fetch polyfill

window.fetch polyfill This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to uphold this code. [co

null 38 Sep 11, 2020
A polyfill for ES6-style Promises

ES6-Promise (subset of rsvp.js) This is a polyfill of the ES6 Promise. The implementation is a subset of rsvp.js extracted by @jakearchibald, if you'r

Stefan Penner 7.3k Dec 28, 2022
Fast and lightweight dependency-free vanilla JavaScript polyfill for native lazy loading / the awesome loading='lazy'-attribute.

loading="lazy" attribute polyfill Fast and lightweight vanilla JavaScript polyfill for native lazy loading, meaning the behaviour to load elements rig

Maximilian Franzke 571 Dec 30, 2022
Unstyled, dev error overlays for SolidJS

solid-error-overlay Unstyled, headless Error Overlay for SolidJS Install npm i solid-error-overlay yarn add solid-error-overlay pnpm add solid-error-o

Alexis H. Munsayac 20 Dec 29, 2022
A Little explanation of the famous Javascript parseInt(0.0000005); error meme.

Explaining the meme Internet is made of millions of memes flowing everyday, so, devs create a ton of new images showing how their code doesn't work, t

akrck02 2 Feb 3, 2022