es-shims / error-cause Goto Github PK
View Code? Open in Web Editor NEWAn ES-spec-compliant shim/polyfill/replacement for the `.cause` property on all Error types that works as far down as ES3
License: MIT License
An ES-spec-compliant shim/polyfill/replacement for the `.cause` property on all Error types that works as far down as ES3
License: MIT License
const e = new Error('message!', { cause: 'bugs' });
assert(e instanceof Error);
assert(e.cause === 'bugs');
As discussed eg here tc39/proposal-error-cause#21 the main intended purpose is to wrap/chain caught errors, so in at least 80% of the cases the cause
will likely be an Error
, at least from the intent of the spec.
Having an example that hints that causes are mainly/only intended to be strings adds needless confusion.
I would propose an example similar to mine here: https://github.com/voxpelli/pony-cause#errorwithcause-creating-an-error-with-a-cause
By sending in a caught exception one avoids confusing people about what exactly the type sent in is supposed to be and instead shows that itβs supposed to be whatever a catch can catch.
Currently the error implementation overwrites constructor, destroying any value that may already be in it.
error-cause/Error/implementation.js
Line 15 in 463e17f
This creates problems down the road, since errors usually need to know their constructor as they use it to eliminate stack frames including and above their constructor in the stack trace. The current implementation makes that impossible.
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These branches will be created by Renovate only once you click their checkbox below.
eslint
to v8.57.0eslint
to v9nyc
to v15.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
package.json
call-bind ^1.0.7
define-properties ^1.2.1
es-abstract ^1.23.3
es-aggregate-error ^1.0.13
es-errors ^1.3.0
globalthis ^1.0.3
has-property-descriptors ^1.0.2
@es-shims/api ^2.5.0
@ljharb/eslint-config ^21.1.0
aud ^2.0.4
auto-changelog ^2.4.0
eslint =8.8.0
evalmd ^0.0.19
function.prototype.name ^1.1.6
has-strict-mode ^1.0.1
in-publish ^2.0.1
npmignore ^0.3.1
nyc ^10.3.2
safe-publish-latest ^2.0.0
tape ^5.7.5
node >= 0.4
There are no types, so constructing an error this way in a project with types is still a type error. The needed type is:
interface Error {
new (reason: string, options?: { cause?: unknown }): Error;
cause: unknown;
}
Are there any existing examples of how to handle types correctly for both pure (const { Error } = require('error-cause')
) and impure (require('error-cause/auto')
) usages?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.