Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-dev-overlay): export getErrorByType and add preventDisplay…
… prop (#34237) Report full parsed runtime errors over error bus, accepts preventDisplay prop to avoid showing error messages inline, while still reporting errors over the bus. Basically, we want to handle the parsed error/stack differently in Next Live, showing a modal that sits above the content and allows users to report the issue to us. We want to have that stack trace in the issue report, so I added a new event `unhandled-error-full`. The `preventDisplay` prop then just lets us output our own modal instead of showing the error inline, but still renders the `<RuntimeErrors />` component so it can fetch the stack and report it over the bus. This isn't *beautiful* code per-se, but I think doing it really right would require a pretty intense re-structure of this module. I think ideally we'd have export a function to fetch of the stack that we can just expose separately - that fetch currently happens in a sub-sub-component (DevOverlay > Errors > RuntimeError). But that re-write is pretty high effort, would still require much of what we do here anyway, and would just to get a slightly less awkward API in a not very high-use area. So leaving it as-is for now, happy to revisit though if we want. ## Feature - [x] Related issues linked using `fixes #number` Fixes an issue with Next Live #290. ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
68 additions
and
40 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-dev-overlay/src/internal/container/RuntimeError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/react-dev-overlay/src/internal/helpers/getErrorByType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TYPE_UNHANDLED_ERROR, TYPE_UNHANDLED_REJECTION } from '../bus' | ||
import { SupportedErrorEvent } from '../container/Errors' | ||
import { isNodeError } from './nodeStackFrames' | ||
import { getOriginalStackFrames, OriginalStackFrame } from './stack-frame' | ||
|
||
export type ReadyRuntimeError = { | ||
id: number | ||
runtime: true | ||
error: Error | ||
frames: OriginalStackFrame[] | ||
} | ||
|
||
export async function getErrorByType( | ||
ev: SupportedErrorEvent | ||
): Promise<ReadyRuntimeError> { | ||
const { id, event } = ev | ||
switch (event.type) { | ||
case TYPE_UNHANDLED_ERROR: | ||
case TYPE_UNHANDLED_REJECTION: { | ||
return { | ||
id, | ||
runtime: true, | ||
error: event.reason, | ||
frames: await getOriginalStackFrames( | ||
isNodeError(event.reason), | ||
event.frames | ||
), | ||
} | ||
} | ||
default: { | ||
break | ||
} | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _: never = event | ||
throw new Error('type system invariant violation') | ||
} |