Skip to content
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

Fix/Improve processWindowErrorEvent #29407

Merged
merged 16 commits into from
Feb 28, 2024
Merged

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Feb 26, 2024

  • e.error can be undefined in some cases which would raise an error inside this error handler, fixed that.
  • The displayed message mentions looking into the console, but in my case of error from ResizeObserver there was nothing there, so add this logging. I think this logging was once there but got lost during refactoring.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 26, 2024
@silverwind silverwind added the backport/v1.21 This PR should be backported to Gitea 1.21 label Feb 26, 2024
@silverwind silverwind changed the title Improve processWindowErrorEvent Fix/Improve processWindowErrorEvent Feb 26, 2024
@silverwind
Copy link
Member Author

Maybe browser does the logging, but only if there is e.error, need to test.

@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 Feb 26, 2024
@silverwind silverwind marked this pull request as draft February 26, 2024 10:21
@silverwind
Copy link
Member Author

Putting draft until I have confirmed above behaviour. Definitely should backport this, otherwise some "errors" will cause errors in inside this error handler.

@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 Feb 26, 2024
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 26, 2024
@silverwind
Copy link
Member Author

silverwind commented Feb 26, 2024

Rewrote the function, now it truly handles all cases and the comments accurately describe what it does.

Flashes:
Screenshot 2024-02-26 at 20 14 57

Console:
Screenshot 2024-02-26 at 20 15 04

@silverwind silverwind marked this pull request as ready for review February 26, 2024 19:17
web_src/js/bootstrap.js Outdated Show resolved Hide resolved
@silverwind
Copy link
Member Author

As per mozilla-mobile/firefox-ios#10817 (comment), the IOS Firefox issue classifies into the !err category, so it's an error event, not an error and we can use the same handler that catches the ResizeObserver events. I added some links to the comment above it and made it not show any error event messages in production.

@silverwind
Copy link
Member Author

silverwind commented Feb 27, 2024

I don't like this change. Because "e" could be anything by design.

But I won't block it.

I know you don't like such destructuring, but ErrorEvent and its properties are well defined, including in the HTML standard, so I see no issue.

@silverwind
Copy link
Member Author

The handler also receives PromiseRejectionEvent and I see its reason property is not guaranteed to be an Error, so it could be improved to handle that case.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 27, 2024

I know you don't like such destructuring

Not really. The real problem is Because "e" could be anything by design.. Before the old code (before #29303) was quite straightforward: if this error, do this, if that error, do that. But the new code just mixed everything together. I don't like making readers "guess" what the type/value there should be.

@wxiaoguang
Copy link
Contributor

ps: the last time I said "no" to such syntax, the reason is the same: it make code unclear (#25253 (comment)), and introduced new bugs #25253 (comment)

@silverwind
Copy link
Member Author

I can restore the previous type check, no problem.

@silverwind silverwind marked this pull request as draft February 27, 2024 16:13
@silverwind
Copy link
Member Author

I decided against type check as there is no overlap in properties between ErrorEvent and PromiseRejectionEvent, so it would unnecessarily bloat the code. I fixed the jsDoc, added a typecheck for Error before accessing stack, and tweaked the comment again.

Everything works as expected:

Screenshot 2024-02-27 at 21 18 52

@silverwind silverwind marked this pull request as ready for review February 27, 2024 20:20
@silverwind
Copy link
Member Author

silverwind commented Feb 27, 2024

Before the old code (before #29303) was quite straightforward: if this error, do this, if that error, do that. But the new code just mixed everything together. I don't like making readers "guess" what the type/value there should be.

It's pretty straightforward already. Could be made even more so by splitting into two handler functions hat converge into a logging function, but I think would be in overengineering territory. I don't see the current function as hard to read just because of this error ?? reason, both properties serve the same purpose.

@silverwind
Copy link
Member Author

@delvh @yardenshoham maybe you want to give this another look as it has changed a bit since your reviews. If there no further objections, I will merge this soon.

web_src/js/bootstrap.js Outdated Show resolved Hide resolved
@yardenshoham
Copy link
Member

Please recommend ways to test

@silverwind
Copy link
Member Author

silverwind commented Feb 28, 2024

Can be tested by installing Violentmonkey with such userscripts:

// ==UserScript==
// @name        Gitea error trigger 1
// @match       http://localhost:3000/*
// ==/UserScript==
setTimeout(() => {
  throw new Error("sync error from userscript");
}, 10000)

const divElem = document.querySelector(".repo-header");
const resizeObserver = new ResizeObserver((entries) => {
  for (const entry of entries) {
    entry.target.style.width = entry.contentBoxSize[0].inlineSize + 10 + "px";
  }
});
resizeObserver.observe(divElem);
// ==UserScript==
// @name        Gitea error trigger 2
// @match       http://localhost:3000/*
// ==/UserScript==
(async () => {
  throw new Error("async error from userscript");
})()

@yardenshoham
Copy link
Member

I can confirm I see the errors
image
image

@silverwind
Copy link
Member Author

silverwind commented Feb 28, 2024

If you go on a repo page, you should also see the proper ResizeObserver error :)

@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 28, 2024
@silverwind silverwind enabled auto-merge (squash) February 28, 2024 22:16
@silverwind silverwind merged commit 6d9b725 into go-gitea:main Feb 28, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.22.0 milestone Feb 28, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Feb 28, 2024
- `e.error` can be undefined in some cases which would raise an error
inside this error handler, fixed that.
- The displayed message mentions looking into the console, but in my
case of error from `ResizeObserver` there was nothing there, so add this
logging. I think this logging was once there but got lost during
refactoring.
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Feb 28, 2024
6543 pushed a commit that referenced this pull request Feb 29, 2024
Backport #29407 by @silverwind

- `e.error` can be undefined in some cases which would raise an error
inside this error handler, fixed that.
- The displayed message mentions looking into the console, but in my
case of error from `ResizeObserver` there was nothing there, so add this
logging. I think this logging was once there but got lost during
refactoring.

Co-authored-by: silverwind <me@silverwind.io>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 29, 2024
* giteaofficial/main: (23 commits)
  Fix wrong test usage of `AppSubURL` (go-gitea#29459)
  Improve contrast on blame timestamp, fix double border (go-gitea#29482)
  Fix/Improve `processWindowErrorEvent` (go-gitea#29407)
  Apply compact padding to small buttons with svg icons (go-gitea#29471)
  Fix counter display number incorrectly displayed on the page (go-gitea#29448)
  Fix incorrect user location link on profile page (go-gitea#29474)
  Fix workflow trigger event bugs (go-gitea#29467)
  Fix URL calculation in clone input box (go-gitea#29470)
  Remove jQuery from the "find file" page (go-gitea#29456)
  Move generate from module to service (go-gitea#29465)
  The job should always run when `if` is `always()` (go-gitea#29464)
  Recolor dark theme to blue shade (go-gitea#29283)
  Let ctx.FormOptionalBool() return optional.Option[bool] (go-gitea#29461)
  Implement actions badge svgs (go-gitea#28102)
  Fix missed return (go-gitea#29450)
  Use tailwind instead of `gt-[wh]-` helper classes (go-gitea#29423)
  Lock issues and pulls faster (go-gitea#29436)
  Allow to change primary email before account activation (go-gitea#29412)
  Update docs about `DEFAULT_ACTIONS_URL` (go-gitea#29442)
  Only use supported sort order for "explore/users" page (go-gitea#29430)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants