Repository navigation
fix(core): handle uncaught native keyboard exceptions - #27514
Conversation
|
|
|
@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? |
| getResizeMode(): Promise<KeyboardResizeOptions | undefined> { | ||
| const engine = this.getEngine(); | ||
| if (!engine || !engine.getResizeMode) { | ||
| if (!isPlatform('ios') || !engine?.getResizeMode) { |
There was a problem hiding this comment.
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.
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.
liamdebeasi
left a comment
There was a problem hiding this comment.
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?
undefinedif the plugin method is unavailable.Does this introduce a breaking change?
Other information
Dev-build:
7.0.8-dev.11684444351.1b1ab142(outdated)