-
Notifications
You must be signed in to change notification settings - Fork 28
fix: npm install warning, onboarding audit telemetry, and dashboard error noise #560
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5731174
fix: stop shipping npm lifecycle scripts
chhhee10 479d33e
fix(audit): report the onboarding auto-audit to PostHog
chhhee10 b7e24d3
fix(dashboard): report only our own errors, not browser extensions'
chhhee10 5daad39
fix(telemetry): give install reporting a 5s ceiling, not 2s
chhhee10 ced8e13
fix(install-check): split prerelease identifiers on dots only
chhhee10 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * End-to-end wiring for the dashboard's global error listeners: real window | ||
| * events in, capture decisions out. | ||
| * | ||
| * The bug this guards: these listeners are page-global, so browser extensions | ||
| * sharing the page had their failures reported as failproofai's. A live | ||
| * MetaMask rejection reached PostHog as an unhandled_rejection. | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { render } from "@testing-library/react"; | ||
| import { GlobalErrorListeners } from "@/app/components/global-error-listeners"; | ||
|
|
||
| const h = vi.hoisted(() => ({ captureClientEvent: vi.fn() })); | ||
| vi.mock("@/lib/client-telemetry", () => ({ captureClientEvent: h.captureClientEvent })); | ||
|
|
||
| const APP = window.location.origin; | ||
|
|
||
| /** Dispatch a real unhandledrejection event with the given reason. */ | ||
| function rejectWith(reason: unknown) { | ||
| const event = new Event("unhandledrejection") as Event & { reason: unknown }; | ||
| event.reason = reason; | ||
| window.dispatchEvent(event); | ||
| } | ||
|
|
||
| /** Dispatch a real error event carrying `error` and `filename`. */ | ||
| function throwWith(error: Error | undefined, filename: string) { | ||
| const event = new Event("error") as Event & { | ||
| error?: Error; | ||
| filename: string; | ||
| message: string; | ||
| lineno: number; | ||
| colno: number; | ||
| }; | ||
| event.error = error; | ||
| event.filename = filename; | ||
| event.message = error?.message ?? "boom"; | ||
| event.lineno = 1; | ||
| event.colno = 1; | ||
| window.dispatchEvent(event); | ||
| } | ||
|
|
||
| function errorFrom(origin: string, message: string): Error { | ||
| const err = new Error(message); | ||
| err.stack = `Error: ${message}\n at fn (${origin}/_next/static/chunks/main.js:1:1)`; | ||
| return err; | ||
| } | ||
|
|
||
| describe("GlobalErrorListeners", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("reports an unhandled rejection thrown by our own code", () => { | ||
| render(<GlobalErrorListeners />); | ||
|
|
||
| rejectWith(errorFrom(APP, "state is undefined")); | ||
|
|
||
| expect(h.captureClientEvent).toHaveBeenCalledWith( | ||
| "unhandled_rejection", | ||
| expect.objectContaining({ error_message: "state is undefined" }), | ||
| ); | ||
| }); | ||
|
|
||
| // The exact production case that prompted this filter. | ||
| it("ignores MetaMask's rejection instead of reporting it as ours", () => { | ||
| render(<GlobalErrorListeners />); | ||
|
|
||
| const metamask = new Error("Failed to connect to MetaMask"); | ||
| metamask.name = "i"; | ||
| metamask.stack = | ||
| "i: Failed to connect to MetaMask\n at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/inpage.js:1:1"; | ||
| rejectWith(metamask); | ||
|
|
||
| expect(h.captureClientEvent).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("ignores a rejection with no stack to attribute it by", () => { | ||
| render(<GlobalErrorListeners />); | ||
|
|
||
| rejectWith("just a string"); | ||
|
|
||
| expect(h.captureClientEvent).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("reports an uncaught exception from our own script", () => { | ||
| render(<GlobalErrorListeners />); | ||
|
|
||
| throwWith(errorFrom(APP, "render failed"), `${APP}/_next/static/chunks/main.js`); | ||
|
|
||
| expect(h.captureClientEvent).toHaveBeenCalledWith( | ||
| "unhandled_exception", | ||
| expect.objectContaining({ error_message: "render failed" }), | ||
| ); | ||
| }); | ||
|
|
||
| it("ignores an uncaught exception from an extension's script", () => { | ||
| render(<GlobalErrorListeners />); | ||
|
|
||
| throwWith(undefined, "chrome-extension://abc/inpage.js"); | ||
|
|
||
| expect(h.captureClientEvent).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("stops listening once unmounted", () => { | ||
| const { unmount } = render(<GlobalErrorListeners />); | ||
| unmount(); | ||
|
|
||
| rejectWith(errorFrom(APP, "after unmount")); | ||
|
|
||
| expect(h.captureClientEvent).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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,111 @@ | ||
| // @vitest-environment node | ||
| /** | ||
| * Attribution for browser errors. | ||
| * | ||
| * The bug this guards: window's error/unhandledrejection listeners are | ||
| * page-global, so browser extensions injected into the dashboard reported their | ||
| * failures as ours. A live MetaMask rejection ("Failed to connect to MetaMask") | ||
| * arrived in PostHog as a failproofai unhandled_rejection. | ||
| */ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { classifyErrorOrigin, isAppError } from "../../lib/error-origin"; | ||
|
|
||
| const APP = "http://localhost:8020"; | ||
|
|
||
| describe("classifyErrorOrigin", () => { | ||
| describe("browser extensions", () => { | ||
| // The exact shape observed in production. | ||
| it("classifies the real MetaMask rejection as an extension error", () => { | ||
| const stack = | ||
| "i: Failed to connect to MetaMask\n" + | ||
| " at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/inpage.js:1:12345"; | ||
|
|
||
| expect(classifyErrorOrigin({ stack, appOrigin: APP })).toBe("extension"); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["chrome", "chrome-extension://abc/inpage.js:1:1"], | ||
| ["firefox", "moz-extension://abc/content.js:1:1"], | ||
| ["safari", "safari-web-extension://abc/injected.js:1:1"], | ||
| ["edge", "ms-browser-extension://abc/script.js:1:1"], | ||
| ])("recognises %s extension frames", (_browser, frame) => { | ||
| expect(classifyErrorOrigin({ stack: `Error: x\n at ${frame}`, appOrigin: APP })).toBe( | ||
| "extension", | ||
| ); | ||
| }); | ||
|
|
||
| // Matching the shared `-extension://` suffix, not a vendor list, so a new | ||
| // browser's scheme is filtered without a code change. | ||
| it("recognises an unknown vendor's extension scheme", () => { | ||
| expect( | ||
| classifyErrorOrigin({ stack: "at future-extension://abc/x.js:1:1", appOrigin: APP }), | ||
| ).toBe("extension"); | ||
| }); | ||
|
|
||
| it("uses the filename when there is no stack", () => { | ||
| expect( | ||
| classifyErrorOrigin({ filename: "chrome-extension://abc/inpage.js", appOrigin: APP }), | ||
| ).toBe("extension"); | ||
| }); | ||
|
|
||
| // An error routed through an extension is the extension's problem, even | ||
| // though one of our frames appears further down the stack. | ||
| it("treats a mixed stack as an extension error", () => { | ||
| const stack = | ||
| "Error: boom\n" + | ||
| " at chrome-extension://abc/inpage.js:1:1\n" + | ||
| ` at fn (${APP}/_next/static/chunks/main.js:2:2)`; | ||
|
|
||
| expect(classifyErrorOrigin({ stack, appOrigin: APP })).toBe("extension"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("our own dashboard", () => { | ||
| it("classifies a stack from our origin as an app error", () => { | ||
| const stack = `TypeError: x is not a function\n at Page (${APP}/_next/static/chunks/page.js:1:1)`; | ||
|
|
||
| expect(classifyErrorOrigin({ stack, appOrigin: APP })).toBe("app"); | ||
| }); | ||
|
|
||
| it("classifies a filename from our origin as an app error", () => { | ||
| expect( | ||
| classifyErrorOrigin({ filename: `${APP}/_next/static/chunks/main.js`, appOrigin: APP }), | ||
| ).toBe("app"); | ||
| }); | ||
|
|
||
| it("attributes correctly on a non-default origin", () => { | ||
| const origin = "http://127.0.0.1:3999"; | ||
|
|
||
| expect(classifyErrorOrigin({ stack: `at fn (${origin}/x.js:1:1)`, appOrigin: origin })).toBe( | ||
| "app", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("unattributable", () => { | ||
| it("returns unknown when there is no location information at all", () => { | ||
| expect(classifyErrorOrigin({ appOrigin: APP })).toBe("unknown"); | ||
| expect(classifyErrorOrigin({ stack: "", filename: "", appOrigin: APP })).toBe("unknown"); | ||
| expect(classifyErrorOrigin({ stack: " ", appOrigin: APP })).toBe("unknown"); | ||
| }); | ||
|
|
||
| // The opaque cross-origin error — nothing in it to debug. | ||
| it("returns unknown for a bare cross-origin 'Script error.'", () => { | ||
| expect(classifyErrorOrigin({ stack: "Script error.", appOrigin: APP })).toBe("unknown"); | ||
| }); | ||
|
|
||
| it("returns unknown for a third-party host that is neither ours nor an extension", () => { | ||
| expect( | ||
| classifyErrorOrigin({ stack: "at https://cdn.example.com/x.js:1:1", appOrigin: APP }), | ||
| ).toBe("unknown"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isAppError", () => { | ||
| it("reports only positively-attributed app errors", () => { | ||
| expect(isAppError({ stack: `at fn (${APP}/x.js:1:1)`, appOrigin: APP })).toBe(true); | ||
| expect(isAppError({ stack: "at chrome-extension://abc/x.js:1:1", appOrigin: APP })).toBe(false); | ||
| expect(isAppError({ appOrigin: APP })).toBe(false); | ||
| }); | ||
| }); |
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.