Skip to content

Commit

Permalink
Try marking errors in catch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jul 9, 2021
1 parent 5b68e0e commit 0d5ded6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/connectAdvanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ function subscribeUpdates(
latestStoreState,
lastWrapperProps.current
)
} catch (e) {
} catch (e: unknown) {
error = e
lastThrownError = e
lastThrownError = e as Error | null
}

if (!error) {
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/useSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ function useSelectorWithStoreAndSubscription<TStoreState, TSelectedState>(
} else {
selectedState = latestSelectedState.current
}
} catch (err) {
} catch (err: unknown) {
if (latestSubscriptionCallbackError.current) {
err.message += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\n`
;(
err as Error
).message += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\n`
}

throw err
Expand All @@ -77,12 +79,12 @@ function useSelectorWithStoreAndSubscription<TStoreState, TSelectedState>(

latestSelectedState.current = newSelectedState
latestStoreState.current = newStoreState
} catch (err) {
} catch (err: unknown) {
// we ignore all errors here, since when the component
// is re-rendered, the selectors are called again, and
// will throw again, if neither props nor store state
// changed
latestSubscriptionCallbackError.current = err
latestSubscriptionCallbackError.current = err as Error
}

forceRender()
Expand Down

0 comments on commit 0d5ded6

Please sign in to comment.