Skip to content

Conversation

@6twenty
Copy link

@6twenty 6twenty commented Apr 15, 2021

Fixes #1969 - refer to this issue for background and demo.

This change only affects the developer experience, and only when using the Vue devtools extension (as far as I can tell); it relates to code that is only called when store._devtoolHook is defined.

The code in question deals with catching errors in action promises, so that the devtools hook can be notified by emitting an event. Catching the rejected promise means that the promise needs to be re-rejected so that the user's code can have its own error handling and carry on as if the error had not been caught in the first place.

The original code was re-rejecting the promise by throwing the error. However, throwing an error has a side effect of causing the browser's own devtools to pause when using the "pause on exceptions" feature, because from the browser's perspective this is an uncaught exception - an error has been thrown, and the browser is not concerned about whether this is happening in a promise, or whether the promise rejection is subsequently caught and handled safely. As a result this behaviour can be annoying during development when testing code that should be resilient to promise rejections. However, simply returning a rejected promise (and passing in the error) allows this code to behave exactly the same way but without triggering the browser's "pause on exceptions" behaviour.

6twenty added 2 commits April 15, 2021 17:23
Fixes vuejs#1969

This code was deliberately throwing an error for the sole purpose of re-rejecting a promise that had been caught in order to emit an event for the devtools hook. However, throwing an error will also trigger the native browser devtools' "pause on exception" behaviour because the error is being thrown without a `try..catch` block. In order to re-reject the promise safely we can use Promise.reject() - this gets handled by the promise in the same way as using `throw`, but the browser devtools will not pause.
@6twenty 6twenty changed the title Return a rejected promise instead of throwing an error Return the original promise instead of throwing an error and returning a new rejected promise Apr 20, 2021
@6twenty 6twenty changed the title Return the original promise instead of throwing an error and returning a new rejected promise Return a new rejected promise instead of throwing an error in the devtools action error handler Jun 15, 2021
@6twenty 6twenty changed the title Return a new rejected promise instead of throwing an error in the devtools action error handler Return a new rejected promise instead of throwing an error in the action error handler for devtools Jun 15, 2021
@cuebit cuebit deleted the branch vuejs:3.x April 13, 2022 03:12
@cuebit cuebit closed this Apr 13, 2022
@cuebit cuebit reopened this Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return a rejected promise rather than use throw in actions when registering the devtools hook

4 participants