Skip to content

fix: handle NotAuthenticatedError in error boundary gracefully#2086

Open
jonathanlab wants to merge 1 commit intomainfrom
posthog-code/fix-incorrect-error-boundary-for-unauthenticated-users
Open

fix: handle NotAuthenticatedError in error boundary gracefully#2086
jonathanlab wants to merge 1 commit intomainfrom
posthog-code/fix-incorrect-error-boundary-for-unauthenticated-users

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

Extracted "Not authenticated" errors into a dedicated NotAuthenticatedError class and updated the error boundary to suppress these errors instead of displaying them, allowing the auth state to naturally resolve to show the authentication screen.


Created with PostHog Code

…th state change

Generated-By: PostHog Code
Task-Id: dd3912cb-28de-4bd9-a74b-daef7ae8a22c
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/components/ErrorBoundary.test.tsx:136-162
**Prefer parameterised tests for `isNotAuthenticatedError`**

The three `it` blocks below cover five distinct input/expectation pairs and would be cleaner as a single `it.each` table. The current structure also buries the three `false` assertions inside one test body, making it easy to miss a case. Using `it.each` maps each input to its expected result in one place and is the team's stated preference for tests like these.

Reviews (1): Last reviewed commit: "feat: suppress NotAuthenticatedError in ..." | Re-trigger Greptile

Comment on lines +136 to +162
rerender(
<Boundary>
<Thrower error={null} />
</Boundary>,
);
await user.click(screen.getByRole("button", { name: /try again/i }));
expect(screen.getByText("ok")).toBeInTheDocument();
});
});

describe("isNotAuthenticatedError", () => {
it("matches NotAuthenticatedError instances", () => {
expect(isNotAuthenticatedError(new NotAuthenticatedError())).toBe(true);
});

it("matches plain objects with the same name (e.g. tRPC-serialized errors)", () => {
expect(isNotAuthenticatedError({ name: "NotAuthenticatedError" })).toBe(
true,
);
});

it("does not match unrelated errors", () => {
expect(isNotAuthenticatedError(new Error("Not authenticated"))).toBe(false);
expect(isNotAuthenticatedError(null)).toBe(false);
expect(isNotAuthenticatedError("Not authenticated")).toBe(false);
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Prefer parameterised tests for isNotAuthenticatedError

The three it blocks below cover five distinct input/expectation pairs and would be cleaner as a single it.each table. The current structure also buries the three false assertions inside one test body, making it easy to miss a case. Using it.each maps each input to its expected result in one place and is the team's stated preference for tests like these.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/components/ErrorBoundary.test.tsx
Line: 136-162

Comment:
**Prefer parameterised tests for `isNotAuthenticatedError`**

The three `it` blocks below cover five distinct input/expectation pairs and would be cleaner as a single `it.each` table. The current structure also buries the three `false` assertions inside one test body, making it easy to miss a case. Using `it.each` maps each input to its expected result in one place and is the team's stated preference for tests like these.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants