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: don't throw on bad icons in BrowserWindow constructor #27441

Merged
merged 3 commits into from Jan 25, 2021

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Jan 21, 2021

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

Release Notes

Notes: fix regression that crashed Electron when processing an invalid icon.

Throwing is an unannounced semver/major breaking change, so revert that
behavior but keep the rest of the #26546 refactor.
@ckerr ckerr requested a review from codebytere January 21, 2021 19:15
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 21, 2021
@ckerr ckerr changed the title fix: do not throw if NativeImage conversion fails. fix: don't throw on bad icons in BrowserWindow constructor Jan 21, 2021
@codebytere codebytere added semver/patch backwards-compatible bug fixes target/11-x-y and removed 11-x-y 12-x-y labels Jan 21, 2021
Copy link
Member

@MarshallOfSound MarshallOfSound left a 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.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 22, 2021
@zcbenz zcbenz merged commit 5a8f40a into master Jan 25, 2021
@release-clerk
Copy link

release-clerk bot commented Jan 25, 2021

Release Notes Persisted

fix regression that crashed Electron when processing an invalid icon.

@zcbenz zcbenz deleted the fix-27303-regression-crash-when-invalid-icon-specified branch January 25, 2021 01:24
@trop
Copy link
Contributor

trop bot commented Jan 25, 2021

I was unable to backport this PR to "11-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Jan 25, 2021

I have automatically backported this PR to "12-x-y", please check out #27463

@trop
Copy link
Contributor

trop bot commented Jan 25, 2021

@ckerr has manually backported this PR to "11-x-y", please check out #27478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when icon is set after updating to electron 11.2
4 participants