Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Switch to options bag #25

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ error with contextual message. Besides, no consensus on which property will
representing the cause makes it not feasible for developer tools to revealing
contextual information of causes.

The proposed solution is adding an additional parameter `cause` to the
`Error()` constructor, and the value of the parameter will be assigned to
the error instances as a property. So errors can be chained without
The proposed solution is adding an additional options parameter to the `Error()`
constructor with a `cause` property, the value of which will be assigned
to the error instances as a property. So errors can be chained without
unnecessary and overelaborate formalities on wrapping the errors in
conditions.

```js
async function doJob() {
const rawResource = await fetch('//domain/resource-a')
.catch(err => {
throw new Error('Download raw resource failed', err);
throw new Error('Download raw resource failed', { cause: err });
});
const jobResult = doComputationalHeavyJob(rawResource);
await fetch('//domain/upload', { method: 'POST', body: jobResult })
.catch(err => {
throw new Error('Upload job result failed', err);
throw new Error('Upload job result failed', { cause: err });
});
}

Expand All @@ -87,6 +87,8 @@ assigned to newly constructed error instances with the name `fileName` and
`lineNumber` respectively.

However, no standard on either ECMAScript or Web were defined on such behavior.
Since the second parameter under this proposal must be an object with a `cause`
property, it will be distinguishable from a string.

## FAQs

Expand Down