-
Notifications
You must be signed in to change notification settings - Fork 54
feat(notifications): inspectable error toasts with details dialog #3247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+717
−75
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5883b97
feat(notifications): inspectable error toasts with details dialog
adamleithp 924e893
fix(notifications): route raw-error toasts through inspectable toastE…
adamleithp 0e80e30
fix(notifications): clamp overflowing toast description, tidy error d…
adamleithp 37d3cd7
fix(notifications): address review comments
adamleithp be90273
preserve error cause, cycles and suffixes
charlesvien bb4daf1
handle zero maxEntries in log capture
charlesvien fd75b61
clear captured logs on logout
charlesvien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
109 changes: 109 additions & 0 deletions
109
packages/ui/src/features/notifications/ErrorDetailsDialog.tsx
This file contains hidden or 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,109 @@ | ||
| import { | ||
| Badge, | ||
| Button, | ||
| Dialog, | ||
| DialogContent, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@posthog/quill"; | ||
| import { CodeBlock } from "@posthog/ui/primitives/CodeBlock"; | ||
| import { openTaskInput } from "@posthog/ui/router/useOpenTask"; | ||
| import { formatCapturedLogs } from "@posthog/ui/shell/logCapture"; | ||
| import { serializeError, useErrorDetailsStore } from "./errorDetails"; | ||
|
|
||
| // Keep the create-task prompt readable: the full 500-entry buffer belongs in | ||
| // the downloaded bundle, not in a composer draft. | ||
| const TASK_PROMPT_LOG_ENTRIES = 100; | ||
|
|
||
| function buildBundle( | ||
| title: string, | ||
| occurredAt: number, | ||
| prettyError: string, | ||
| ): string { | ||
| return [ | ||
| `# ${title}`, | ||
| `Occurred at: ${new Date(occurredAt).toISOString()}`, | ||
| "", | ||
| "## Error", | ||
| prettyError, | ||
| "", | ||
| "## Recent logs", | ||
| formatCapturedLogs(), | ||
| "", | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| // Global inspector behind every error toast's "Details" action: the full | ||
| // pretty-printed payload the toast had no room for, a downloadable | ||
| // error-plus-logs bundle, and (dev builds only) a one-click task prefilled | ||
| // with the same context. | ||
| export function ErrorDetailsDialog() { | ||
| const detail = useErrorDetailsStore((s) => s.detail); | ||
| const close = useErrorDetailsStore((s) => s.close); | ||
| if (!detail) return null; | ||
|
|
||
| const prettyError = serializeError(detail.error); | ||
|
|
||
| const handleDownload = () => { | ||
| const bundle = buildBundle(detail.title, detail.occurredAt, prettyError); | ||
| const blob = new Blob([bundle], { type: "text/markdown" }); | ||
| const url = URL.createObjectURL(blob); | ||
| const anchor = document.createElement("a"); | ||
| anchor.href = url; | ||
| anchor.download = `posthog-code-error-${detail.occurredAt}.md`; | ||
| anchor.click(); | ||
| URL.revokeObjectURL(url); | ||
| }; | ||
|
|
||
| const handleCreateTask = () => { | ||
| close(); | ||
| openTaskInput({ | ||
| initialPrompt: [ | ||
| `Investigate this error from the PostHog Code app: ${detail.title}`, | ||
| "", | ||
| "## Error", | ||
| "```", | ||
| prettyError, | ||
| "```", | ||
| "", | ||
| "## Recent logs", | ||
| "```", | ||
| formatCapturedLogs({ maxEntries: TASK_PROMPT_LOG_ENTRIES }), | ||
| "```", | ||
| ].join("\n"), | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open onOpenChange={(open) => !open && close()}> | ||
| <DialogContent className="w-[min(720px,calc(100vw-32px))] max-w-[720px] sm:max-w-[720px]"> | ||
| <DialogHeader> | ||
| <DialogTitle>{detail.title}</DialogTitle> | ||
| </DialogHeader> | ||
| <div className="max-h-[55vh] overflow-y-auto px-1"> | ||
| <CodeBlock size="1">{prettyError}</CodeBlock> | ||
| </div> | ||
| <DialogFooter> | ||
| {import.meta.env.DEV && ( | ||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| onClick={handleCreateTask} | ||
| className="gap-2 sm:mr-auto" | ||
| > | ||
| Create task from error | ||
| <Badge variant="warning">Dev</Badge> | ||
| </Button> | ||
| )} | ||
| <Button variant="outline" size="sm" onClick={handleDownload}> | ||
| Download error + logs | ||
| </Button> | ||
| <Button variant="primary" size="sm" onClick={close}> | ||
| Close | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.