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: don't throw on bad icons in BrowserWindow constructor #27441
fix: don't throw on bad icons in BrowserWindow constructor #27441
Conversation
Throwing is an unannounced semver/major breaking change, so revert that behavior but keep the rest of the #26546 refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short term this works and makes sense, I've discussed the underlying issue here with a bunch of people though and we really should find a way to solve this generically for all constructors and all theoretical errors.
The problem is specific to super c++ constructors that are bound to JS constructors. i.e. this case of BaseWindow
being "supered" to BrowserWindow
. There is no way for the C++ BrowserWindow
constructor to know that BaseWindow
threw a JS exception and should early terminate, also early termination of a C++ constructor is weird and not easy to follow behavior.
My long term suggestion would be to refactor our gin'ed classes into having an empty constructor, an IsInitialized()
check (which should be hard CHECK
'ed in the gin converter) and move all the initialization logic to an Initialize
method that can return a boolean for success. This would all be hidden from end users (you'd still call new BrowserWindow()
but under the hood that should create the new C++ class and call Initialize
early terminating at each class layer if the parent class Initialize
failed. There are probably flaws in this plan but we should definitely figure out a way to do it.
Release Notes Persisted
|
I was unable to backport this PR to "11-x-y" cleanly; |
I have automatically backported this PR to "12-x-y", please check out #27463 |
Description of Change
Fixes #27303.
Don't throw exceptions in the BrowserWindow constructor when fed an invalid image.
This change adds a new parameter to TryConvert that specifies what to do on error -- to throw or to warn. The default is to throw.
This change also adds a new protected method SetIconImpl() that is basically the old SetIcon() + that new parameter. This was added instead of appending a switch to SetIcon() because the latter is directly callable as public API and it doesn't make sense to expose this switch. SetIcon() is now a one-liner that calls SetIconImpl() with 'throw' behavior. The BrowserWindow constructor calls SetIconImpl() with 'warn' behavior.
CC @codebytere
Checklist
npm test
passesRelease Notes
Notes: fix regression that crashed Electron when processing an invalid icon.