feat(errors): report action with error digest and 404 detection - #1794
Open
bilhokista wants to merge 4 commits into
Open
feat(errors): report action with error digest and 404 detection#1794bilhokista wants to merge 4 commits into
bilhokista wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1565.
One requirement was already met
"Try again that re-runs the failed route loader without full reload" already works:
RouteErrorStatewires its button to theresetprop, which is Next.js's own boundary reset, and the existing test inroute-error-state.test.tsxalready assertsresetis invoked on click. I left that untouched rather than reimplementing it, and the existing test still passes unchanged.The two genuinely missing pieces were the report action and the 404 distinction.
Report issue
A new "Report issue" action opens the tracker with the context prefilled. Two pure functions do the work so they can be tested without the DOM:
buildReportBody(context)— route, path, digest reference, timestamp, and error message, followed by a prompt asking what the user was doing.buildReportUrl(baseUrl, context)— appends the parameters, usingtitle/bodyfor a tracker URL andsubject/bodyfor amailto:address, and appending correctly when the base URL already carries a query string.Two deliberate choices:
Reference: none, rather than omitting the line. An absent field reads as an oversight; an explicit "none" tells the maintainer the error genuinely arrived without one.The link opens in a new tab, so an in-flight recovery attempt on the page is not thrown away.
Distinguishing 404 from runtime errors
A route that calls
notFound(), or a loader surfacing a 404 from the API, lands in the same error boundary as a genuine crash. Until now both rendered "hit an unexpected problem" with a Try again button — which for a mistyped URL invites the user to retry something that can never succeed.isNotFoundErrornow routes those to the existingAppNotFoundcomponent. It is deliberately narrow: it matches Next'sNEXT_NOT_FOUNDdigest and an explicit numericstatus/statusCodeof 404, not the substring "404" in a message. A substring match would send a real failure whose message happens to mention a 404 sub-resource to the wrong screen; there is a test for exactly that case.A missing page is also no longer logged via
console.erroras an application fault.Configuration
env.ERROR_REPORT_URLreadsNEXT_PUBLIC_ERROR_REPORT_URL, documented in.env.example. This is the one judgement call I would like checked: I defaulted it tohttps://github.com/Arena1X/InsightArena/issues/new, this project's own tracker. That is right for this repository, but a fork or a white-label deployment would want its own destination — hence the env var. If you would rather the action be hidden entirely when nothing is configured, that is a small change.Tests
route-error-state.test.tsxgrows from 1 case to 18: 4 onisNotFoundError(including the substring trap), 4 onbuildReportBody, 4 onbuildReportUrl(tracker, mailto, existing query string, absent digest), and 4 rendering cases covering the report link's href andrel, the no-digest path, the 404 screen replacing the crash message, and the absence of a console error for a missing page.Honest note on verification: I could not run the frontend Vitest suite locally (no full workspace install). All changed files were parsed with the TypeScript compiler API, and the three exported helpers were transpiled and executed standalone against 24 assertions — all passed. One of those assertions checks that the report body is genuinely multi-line, because I hit and fixed an escaping bug there while writing it and wanted a guard against the regression. The four rendering cases need CI.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CrfEY1tvXrbeMDAUzxfuk7