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

[Head API]: Fixed runtime crash of monkey-patched console.error #39020

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JustFly1984
Copy link

I've encountered an error in monkey-patched console.error. Monkey-patching native functions is bad practice in general, but in this case, I got unexpected runtime crash while handling a failed case of try catch in my code.

I've added try/catch block inside the monkey-patched function, so it handles errors gracefully.

Please review.

This is first of the series of PR I'm making, based on my previous research and huge PR

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 23, 2024
return undefined
}
} catch (e) {
originalConsoleError(...args, e)
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't logging in this catch block and later on line 77 not result in mostly duplicated log lines (with first line showing caught error here)?

I don't think logging error we are catching here is beneficial to users overall and maybe just getting behavior of not "filtering out" calls that error out would be enough? As in we only want to filter out one specific line that wouldn't be throwing, but everything else should be just passed through to original console.error regardless if the checks throw or not

Copy link
Author

Choose a reason for hiding this comment

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

@pieh In my case, I'm trying to console.error(an actual error), but it crashes with error inside the mocked function and I have no idea what exactly crashed and what I was trying to see as result of console.error. In both dev and prod.
Better approach would be not monkey-patching console.error at all, but that is not my call
Is there a specific reason to do that for Head api? Can we just remove whole thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants