Skip to content

Fix relative-time error and improve global error handler#37241

Merged
wxiaoguang merged 20 commits intogo-gitea:mainfrom
silverwind:relative-time-invalid-lang
Apr 21, 2026
Merged

Fix relative-time error and improve global error handler#37241
wxiaoguang merged 20 commits intogo-gitea:mainfrom
silverwind:relative-time-invalid-lang

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Apr 16, 2026

  1. Fixes: relative-time error invalid language tag: "undefined" in playwright #37239
  2. Enhance global error message to show stack trace on click
image

This PR was written with the help of Claude Opus 4.7

`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>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 16, 2026
@silverwind silverwind changed the title Fix relative-time error with invalid navigator.language Fix relative-time error and improve global error handler Apr 16, 2026
silverwind and others added 2 commits April 16, 2026 19:53
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-time locale resolution resilient to invalid navigator.language values and add a regression unit test.
  • Replace showGlobalErrorMessage with showGlobalError(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.

Comment thread web_src/js/modules/errors.ts Outdated
Comment thread web_src/js/modules/errors.ts Outdated
Comment thread web_src/js/modules/errors.ts Outdated
Comment thread web_src/js/modules/errors.ts Outdated
Comment thread tests/e2e/homepage.test.ts Outdated
silverwind and others added 2 commits April 16, 2026 20:35
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>
Comment thread web_src/js/modules/errors.ts Outdated
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>
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

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.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 17, 2026
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Apr 17, 2026

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.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Apr 17, 2026

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.

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


"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.

It is just your guess and imagination that "it needs to show stack for a user who uses a phone".

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Apr 17, 2026

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.

@wxiaoguang
Copy link
Copy Markdown
Contributor

It's more about that I always have to ask users to copy the error from the console

How many times? Where are the related issues?

If you don't like the copy button, we could make it visible on-hover.

I don't accept any more useless change.

@silverwind
Copy link
Copy Markdown
Member Author

How many times? Where are the related issues?

At least 4-5 times, some on GitHub, some on Discord.

I don't accept any more useless change.

It is genuinely needed for debugging.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Apr 17, 2026

Concrete example:

image

User posts only a screenshot of the error without any console output. Errors was deducable from the message via AI, but in case of e is undefined, this won't be possible.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Apr 17, 2026

If copy button is not to your liking, we can use a <details>+<summary> that expands with the stack track on click and maybe add a "Click for details" in place of "Open browser console". Least obtrusive change possible.

@wxiaoguang
Copy link
Copy Markdown
Contributor

Concrete example:
image

User posts only a screenshot of the error without any console output. Errors was deducable from the message via AI, but in case of e is undefined, this won't be possible.

  1. They are contributors, they should know how to correctly report a bug without the "copy" button or duplicate "stack" message.
  2. Most end users should never see the JS error, most JS errors should already have been handled by maintainers during the development.
  3. Even if you have a "copy" button, almost all users still only show you a screenshot (just like your screenshot shows), you still need to tell them "please provide the stacktrace", the same as "open the console and show the stacktrace"

@wxiaoguang
Copy link
Copy Markdown
Contributor

If copy button is not to your liking, we can use a <details>+<summary> that expands with the stack track on click and maybe add a "Click for details" in place of "Open browser console". Least obtrusive change possible.

Can do with a general function like

export function showGlobalErrorMessage(msg: string, msgType: Intent = 'error', details?: string) {
...
}

@silverwind
Copy link
Copy Markdown
Member Author

I will do the details+summary approach like that.

Comment thread web_src/js/modules/errors.test.ts Outdated
Signed-off-by: silverwind <me@silverwind.io>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 21, 2026
Comment thread web_src/css/modules/message.css Outdated
wxiaoguang and others added 2 commits April 21, 2026 08:32
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
@silverwind silverwind requested a review from bircni April 21, 2026 01:40
@lunny lunny added the type/bug label Apr 21, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 21, 2026
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 21, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 21, 2026 06:35
@wxiaoguang wxiaoguang disabled auto-merge April 21, 2026 06:36
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 21, 2026 06:36
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Apr 21, 2026

My only question: Why is single message still centered? Looks inconistent.

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.

@wxiaoguang wxiaoguang merged commit caff989 into go-gitea:main Apr 21, 2026
26 checks passed
@wxiaoguang wxiaoguang deleted the relative-time-invalid-lang branch April 21, 2026 07:53
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 21, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 21, 2026
silverwind added a commit to 6543-forks/gitea that referenced this pull request Apr 21, 2026
…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
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 22, 2026
* 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)
  ...
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* 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
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* 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
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

relative-time error invalid language tag: "undefined" in playwright

6 participants