Skip to content

Commit

Permalink
Rethrowing original errors thrown in selector functions (#1474)
Browse files Browse the repository at this point in the history
* Added optional stacktrace to errors thrown from selector functions

When throwing error from selector function, append original error stacktrace (if present) to new error.

* Rethrowing original errors from selector functions
  • Loading branch information
r3dm1ke authored and timdorr committed Nov 27, 2019
1 parent b198f26 commit 5402f24
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/hooks/useSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ function useSelectorWithStoreAndSubscription(
selectedState = latestSelectedState.current
}
} catch (err) {
let errorMessage = `An error occurred while selecting the store state: ${err.message}.`

if (latestSubscriptionCallbackError.current) {
errorMessage += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\nOriginal stack trace:`
err.message += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\n`
}

throw new Error(errorMessage)
throw err
}

useIsomorphicLayoutEffect(() => {
Expand Down

0 comments on commit 5402f24

Please sign in to comment.