-
Notifications
You must be signed in to change notification settings - Fork 9
How will this conflict with existing solutions like VError? #31
Comments
Also: As a function is valid value for |
The user can |
To determine what? 🙂 Currently, as discussed in #21, the following is valid and fulfills that check as well: const err = new Error('Upload job result failed', { cause: () => 'yay' }); |
True. In that case, would |
Not really, there will likely exist plenty of different What one can do is to use if (ex.cause) {
var cex = typeof (ex.cause) === 'function' ? ex.cause() : ex.cause;
// ...
} I guess what one could do is to mimic |
While true, it's also extremely un-idiomatic. I wouldn't bother trying to be defensive against such code. By analogy, it's also perfectly possible to write |
( My intent with this issue was not to try to change the proposal, but to come up with advice for those who wants to transition from VError to this or have a split ecosystem between the two, so broader than |
That's also extremely un-idiomatic, in just the same way that
Right; my point is that I think |
@bakkot I updated my initial post to make my points clearer and to incorporate the feedback so far |
I'm afraid I didn't see the issue around the assumption. People using verror-like modules or modules would like to printing causes with verror-like (i.e. errors with a callable For point 2, things would not be alleviated whether or not the
This issue is already a problem if people are caring about it. People may set an arbitrary value on the To my view, in pure JavaScript code, there isn't any transition required for existing code to continue to work with verror-like modules. But additionally, people can now assume the |
As long as it doesn't break the current implementation of My only concern, is that right now the polyfill doesn't allow us to test with 'use strict';
require('./cause-polyfill');
const { VError } = require('@netflix/nerror');
let e = new VError({
cause: new Error('test'),
name: 'TestCause'
});
console.info(typeof e.cause); will throw (on this line):
And current error libraries should continue to work moving forward when this proposal is implemented on the engines. |
That's just a bug in the polyfill, which isn't in any sense official (there are no official polyfills). I'm sure there will be more production-ready polyfills at some point that correctly implement the spec and therefore do not throw. |
Is the |
I haven’t published the es-shims one yet, but will be doing so soonish. |
@ljharb hi, any estimate for when a polyfill would be available? |
I've now published a ponyfill here: https://github.com/voxpelli/pony-cause It also includes helpers that makes it easier to make good use of Error Causes + supports both these Error Causes and those from |
@voxpelli nice work! to clarify tho, it's only a "ponyfill" (not that any of us should be using that term) if it's spec-compliant, and making a non-spec ErrorWithCause subclass, as well as calling I've just published https://www.npmjs.com/package/error-cause, which is spec-compliant, and follows the es-shims interface. Given both your VError solution and the existence of spec-compliant polyfills, perhaps this is ready to be closed? |
Having a ponyfill specific name like
proposal-error-cause/polyfill.js Lines 8 to 10 in a002df0
If there’s anything substantial that isn’t spec-compliant in it, feel free to file issues. And yes, let’s close this 👍 |
@voxpelli @ljharb thanks for your work on bringing the implementation to life! I'm going to update the README to guide people to use https://www.npmjs.com/package/error-cause and https://github.com/voxpelli/pony-cause. |
I opened an issue in
VError
(TritonDataCenter/node-verror#81) about this spec as, while I very much look forward to this spec, it seems to be a possible issue that theVError
extension ofError
currently implements a different.cause
than what this proposal proposes, and same goes for@netflix/nerror
.In VError:
In this proposal:
Any current code that assumes that when
.cause
exists it will be of the style ofVError#cause
, will have an issue, as it will try calling something that isn't a function. This probably shouldn't be a problem as one always needs to ensure that one have complete checks, like the one in Bunyan.Any code that assumes that
.cause
will be as defined in this proposal won't have an issue with aVError#cause
value, as it will then just be treated as if the method itself is the cause rather than the returned value of it – which is okay. (This can change if What type of value is "cause" meant to contain? #21 arrives at something else)Type wise there will be an issue as any class that extends
Error
needs to have compatible such extensions, and the@types/verror
definition of.cause
is not compatible with the one in this proposal, so it will fail, as can be exemplified using.stack
I just want to raise this, partly as a way to connect the discussion in eg. VError to a discussion in this proposal.
The text was updated successfully, but these errors were encountered: