-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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(core): handle uncaught native keyboard exceptions #27514
Conversation
Run & review this pull request in StackBlitz Codeflow. |
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.
LGTM
@liamdebeasi I'm going to add you as an additional reviewer since you wrote a lot of the code around this. Any concerns to this approach? |
core/src/utils/native/keyboard.ts
Outdated
@@ -18,7 +20,9 @@ export const Keyboard = { | |||
}, | |||
getResizeMode(): Promise<KeyboardResizeOptions | undefined> { | |||
const engine = this.getEngine(); | |||
if (!engine || !engine.getResizeMode) { | |||
if (!isPlatform('ios') || !engine?.getResizeMode) { |
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.
Are we able to check the UNIMPLEMENTED
value from Capacitor instead of checking the platform?
So something like this:
try {
return engine.getResizeMode();
} catch(e) {
if (e.code === 'UNIMPLEMENTED') {
return Promise.resolve(undefined);
}
// throw the error unchanged if not an unimplemented error
throw e;
}
My concern with the proposed approach is we are coupling our code to implementation details of the Capacitor plugin. Additionally, isPlatform
relies on user agent sniffing which can be spoofed, so that check may not always be correct. Checking the unimplemented state lets us rely on Capacitor to tell us about functionality.
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.
Ooh that's brilliant, I didn't think of that approach!
Yes, we can do something very similar to this. I ended up using a .catch
on the original promise, so when it is chained in the implementation, it will resolve undefined
. It'll swallow the error in the client runtime, but still indicate the unimplemented method invocation in the native bridge logs.
This is a slightly different net result that the original implementation, which doesn't log the console.error
for the unimplemented method invocation (because it isn't executed), but solves the original problem of the uncaught error.
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.
One comment, but otherwise looks good. Thanks for fixing this!
Issue number: Resolves #27503
What is the current behavior?
Ionic Framework wraps the implementation around Capacitor's Keyboard plugin API, to provide additional functionality and behavior "automatically" in Ionic, when the plugin is installed.
Certain methods such as
getResizeMode()
are only available for certain platforms and will cause an error when running in the unsupported platform.Ionic Framework does not check to see if that platform is active before calling potentially unsupported methods, which leads to an exception for scenarios such as this - calling
getResizeMode()
on Android.What is the new behavior?
undefined
if the plugin method is unavailable.Does this introduce a breaking change?
Other information
Dev-build:
7.0.8-dev.11684444351.1b1ab142
(outdated)