Fix relative-time error and improve global error handler#37241
Fix relative-time error and improve global error handler#37241wxiaoguang merged 20 commits intogo-gitea:mainfrom
relative-time error and improve global error handler#37241Conversation
`navigator.language` can be the string `"undefined"` in Playwright Firefox (not just the undefined value), causing `Intl.DateTimeFormat` to throw `RangeError: invalid language tag: "undefined"`. The prior fix in go-gitea#37021 only handled the undefined value. Validate both the `lang` attribute and `navigator.language` through `Intl.Locale` and fall back to `'en'` if both yield invalid tags. Also enhances the global error UI: - Render the error stack trace (hidden, included when copying) - Add a copy-to-clipboard button with icon-swap feedback - Drop the "Open browser console" hint - Expose `copy` i18n key for the button's aria-label Fixes go-gitea#37239 Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
relative-time error with invalid navigator.languagerelative-time error and improve global error handler
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Rename `showGlobalErrorMessage` to `showGlobalError`, accept an `Error` as the first argument, and move the `"JavaScript error:"` / `"JavaScript promise rejection:"` prefix into the function. Replace raw `navigator.clipboard.writeText` with `clippie` and guard rapid clicks from stacking reset timeouts. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a Playwright/headless-only relative-time locale parsing crash and enhances the frontend global error handler to better capture/copy debugging details, plus adds an e2e smoke test to catch homepage JS errors.
Changes:
- Make
relative-timelocale resolution resilient to invalidnavigator.languagevalues and add a regression unit test. - Replace
showGlobalErrorMessagewithshowGlobalError(Error, opts)and extend the global error UI with a copy-to-clipboard button that includes stack traces. - Add a Playwright test intended to ensure the homepage renders without JS errors.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| web_src/js/webcomponents/relative-time.ts | Safer language fallback when locale candidates are invalid. |
| web_src/js/webcomponents/relative-time.test.ts | Adds regression test for invalid navigator.language. |
| web_src/js/modules/errors.ts | New showGlobalError API + copy-with-stack UI + updated error event processing. |
| web_src/js/modules/errors.test.ts | Updates/extends unit tests for new error handler behavior. |
| web_src/js/features/common-page.ts | Migrates warning banners to the new showGlobalError API. |
| web_src/js/bootstrap.ts | Uses showGlobalError for early bootstrap failures. |
| tests/e2e/homepage.test.ts | Adds homepage smoke test asserting no global error UI is rendered. |
| templates/base/head_script.tmpl | Adds i18n.copy string to window.config for the new copy button label. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Keep the public signature as `showGlobalErrorMessage(msg, msgType?, stack?)` with a new third `stack` param. Minimizes the diff against main: bootstrap.ts and common-page.ts revert to their original call shape; only `processWindowErrorEvent` passes the new `stack` arg. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
- Drop the copy button's aria-label (and the newly-added i18n.copy key) so the error UI has no runtime dependency on window.config and works even when bootstrap triggers showGlobalErrorMessage due to a missing window.config. - Preserve newlines in multi-line messages (e.g. the ROOT_URL warning) via tw-whitespace-pre-line on .js-global-error-msg. - Always overwrite .js-global-error-stack so a previously-set stack doesn't linger when a later call has none. - Add networkidle wait to the homepage e2e so async JS errors have time to reach the global handler before the assertion; disable playwright/no-networkidle globally for e2e tests. - Simplify tests: shared beforeEach, drop redundant DOM-structure assertions, remove unneeded teardown plumbing. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Coverage is already provided by the `processWindowErrorEvent renders stack trace` test. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Keep comments and `.toString()` choices consistent with main so the diff focuses on the actual behavioral changes. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
There was a problem hiding this comment.
No, the error message prompt is just for development purpose.
It should not be that complex. The more complex it becomes, the more potential bugs it will have. What if the code causes new errors again?
Do not make things unnecessarily complex.
If you need to read more about the error details, just open the browser's console, just like all the frontend developers do.
|
Stack trace must be accessible somehow because it's vital information and a small copy button achieves that in the least obtrusive way besides rendering it directly. "Open the console" is bad, some browsers might not even have a console, think about tablets or phones. Don't assume every user is on a desktop. |
Do you remember that you had objection when I introduced such "js error message prompt"? But now why you keep making it unnecessarily complex. Developers should open their console, look into the real source code with source map. In production build, your stack trace here is just garbled text
It is just your guess and imagination that "it needs to show stack for a user who uses a phone". |
|
It's more about that I always have to ask users to copy the error from the console than to screenshot/copy only the message because "Foo is undefined" is not debuggable without the stack trace. If you don't like the copy button, we could make it visible on-hover. |
How many times? Where are the related issues?
I don't accept any more useless change. |
At least 4-5 times, some on GitHub, some on Discord.
It is genuinely needed for debugging. |
|
If copy button is not to your liking, we can use a |
|
Can do with a general function like |
|
I will do the details+summary approach like that. |
Just because "it looks better" for "single line" (as you suggested). For > 99% cases, the left-alignment and center-alignment won't appear on the same page at the same time, there won't be "inconsistent" Also, for > 99% cases, you will still only see single line message. The multiple line message is only for some serious errors, very rare cases. |
…n-better * origin/main: (645 commits) When the requested arch rpm is missing fall back to noarch (go-gitea#37236) Fix `relative-time` error and improve global error handler (go-gitea#37241) Enhance styling in actions page (go-gitea#37323) fix(oauth): Error on auth sources with spaces (go-gitea#37327) Fix actions concurrency groups cross-branch leak (go-gitea#37311) Fix bug when accessing user badges (go-gitea#37321) Fix AppFullLink (go-gitea#37325) Update go js dependencies (go-gitea#37312) Update GitHub Actions to latest major versions (go-gitea#37313) Revert "Add WebKit to e2e test matrix (go-gitea#37298)" (go-gitea#37315) Add `form-fetch-action` to some forms, fix "fetch action" resp bug (go-gitea#37305) Move heatmap to first-party code (go-gitea#37262) Use updated yaml fields for snapcraft (go-gitea#37318) Remove dead code identified by `deadcode` tool (go-gitea#37271) Enable strict TypeScript, add `errorMessage` helper (go-gitea#37292) Fix vite manifest update masking build errors (go-gitea#37279) bump snapcraft base (go-gitea#37301) Add WebKit to e2e test matrix (go-gitea#37298) Don't add useless labels which will bother changelog generation (go-gitea#37267) Fix Repository transferring page (go-gitea#37277) ... # Conflicts: # options/locale/locale_en-US.ini # templates/package/content/debian.tmpl
* main: (25 commits) Add URL to `Learn more about blocking a user` (go-gitea#37355) fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288) Add event.schedule context for schedule actions task (go-gitea#37320) Fix typos (go-gitea#37346) Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324) Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270) Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338) Fix URL related escaping for oauth2 (go-gitea#37334) When the requested arch rpm is missing fall back to noarch (go-gitea#37236) Fix `relative-time` error and improve global error handler (go-gitea#37241) Enhance styling in actions page (go-gitea#37323) fix(oauth): Error on auth sources with spaces (go-gitea#37327) Fix actions concurrency groups cross-branch leak (go-gitea#37311) Fix bug when accessing user badges (go-gitea#37321) Fix AppFullLink (go-gitea#37325) Update go js dependencies (go-gitea#37312) Update GitHub Actions to latest major versions (go-gitea#37313) Revert "Add WebKit to e2e test matrix (go-gitea#37298)" (go-gitea#37315) Add `form-fetch-action` to some forms, fix "fetch action" resp bug (go-gitea#37305) Move heatmap to first-party code (go-gitea#37262) ...
* origin/main: (32 commits) fix: commit status reporting (go-gitea#37372) Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356) Fix cmd tests by mocking builtin paths (go-gitea#37369) chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374) Fix button layout shift when collapsing file tree in editor (go-gitea#37363) Update `Block a user` form (go-gitea#37359) Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364) Add URL to `Learn more about blocking a user` (go-gitea#37355) fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288) Add event.schedule context for schedule actions task (go-gitea#37320) Fix typos (go-gitea#37346) Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324) Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270) Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338) Fix URL related escaping for oauth2 (go-gitea#37334) When the requested arch rpm is missing fall back to noarch (go-gitea#37236) Fix `relative-time` error and improve global error handler (go-gitea#37241) Enhance styling in actions page (go-gitea#37323) fix(oauth): Error on auth sources with spaces (go-gitea#37327) Fix actions concurrency groups cross-branch leak (go-gitea#37311) ... # Conflicts: # services/actions/commit_status.go
* origin/main: (204 commits) fix: commit status reporting (go-gitea#37372) Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356) Fix cmd tests by mocking builtin paths (go-gitea#37369) chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374) Fix button layout shift when collapsing file tree in editor (go-gitea#37363) Update `Block a user` form (go-gitea#37359) Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364) Add URL to `Learn more about blocking a user` (go-gitea#37355) fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288) Add event.schedule context for schedule actions task (go-gitea#37320) Fix typos (go-gitea#37346) Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324) Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270) Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338) Fix URL related escaping for oauth2 (go-gitea#37334) When the requested arch rpm is missing fall back to noarch (go-gitea#37236) Fix `relative-time` error and improve global error handler (go-gitea#37241) Enhance styling in actions page (go-gitea#37323) fix(oauth): Error on auth sources with spaces (go-gitea#37327) Fix actions concurrency groups cross-branch leak (go-gitea#37311) ... # Conflicts: # web_src/js/index-domready.ts # web_src/js/markup/content.ts # web_src/js/markup/refissue.ts
* origin/main: (204 commits) fix: commit status reporting (go-gitea#37372) Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356) Fix cmd tests by mocking builtin paths (go-gitea#37369) chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374) Fix button layout shift when collapsing file tree in editor (go-gitea#37363) Update `Block a user` form (go-gitea#37359) Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364) Add URL to `Learn more about blocking a user` (go-gitea#37355) fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288) Add event.schedule context for schedule actions task (go-gitea#37320) Fix typos (go-gitea#37346) Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324) Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270) Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338) Fix URL related escaping for oauth2 (go-gitea#37334) When the requested arch rpm is missing fall back to noarch (go-gitea#37236) Fix `relative-time` error and improve global error handler (go-gitea#37241) Enhance styling in actions page (go-gitea#37323) fix(oauth): Error on auth sources with spaces (go-gitea#37327) Fix actions concurrency groups cross-branch leak (go-gitea#37311) ... Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com> # Conflicts: # web_src/js/index-domready.ts # web_src/js/markup/content.ts # web_src/js/markup/refissue.ts


relative-timeerrorinvalid language tag: "undefined"in playwright #37239This PR was written with the help of Claude Opus 4.7