Skip to content

Commit

Permalink
docs: Add caution about suppressing errors (#174)
Browse files Browse the repository at this point in the history
The TSDoc comment for `createDeferredPromise` has been updated to
include a caution about using the `suppressUnhandledRejection` option.
The comment now explains in more detail why this option is useful, and
why it can be dangerous and should be treated with caution.
  • Loading branch information
Gudahtt authored Mar 13, 2024
1 parent 588f267 commit e58a8d8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export type DeferredPromise<Result = void> = {
/**
* Create a defered Promise.
*
* If the Promise is rejected prior to a handler being added, this can result in an
* `UnhandledPromiseRejection` error. Optionally this can be suppressed with the
* `suppressUnhandledRejection` flag, as it's common to belatedly handle deferred Promises, or to
* ignore them if they're no longer relevant (e.g. related to a cancelled request).
*
* However, be very careful that you have handled the Promise if you do this. Suppressing these
* errors is dangerous, they exist for good reason. An unhandled rejection can hide errors, making
* debugging extremely difficult. They should only be suppressed if you're confident that the
* Promise is always handled correctly, in both the success and failure cases.
*
* @param args - The arguments.
* @param args.suppressUnhandledRejection - This option adds an empty error handler
* to the Promise to suppress the UnhandledPromiseRejection error. This can be
Expand Down

0 comments on commit e58a8d8

Please sign in to comment.