feat: Add additional context on plugin errors
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
- Área
- api, mobile-dev
Línea de trabajo
Comienza en los archivos native-bridge.js nativos de iOS y Android, en el manejo de llamadas almacenadas alrededor de result.error, y luego reproduce los casos UNIMPLEMENTED en la aplicación de ejemplo mínima enlazada. Compara los enfoques disponibles y confirma que el error resultante expone suficiente contexto del plugin y del método para ambos ejemplos de plataforma.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature Request
Description
Currently, the information included in plugin errors doesn't always make it obvious where an error gets triggered, nor which plugin and plugin method is involved. It would be nice if additional information could be added. I'd be happy to provide a PR for this, upon some guidance.
Specifically this applies for UNIMPLEMENTED errors.
For example, we we've been getting the error Error: not implemented. The full stack trace looks like this:
Ultimately, this error got triggered by calling LocalNotifications.listChannels() of the LocalNotifications plugin on iOS. The error is expected as this method isn't implemented on iOS, but we didn't realise this at first.
The problem is that there is no way to know what is causing Error: not implemented just by looking at the error and its stack trace.
The information provided by the error doesn't reveal:
- That the error occurred in the
listChannelsmethod of theLocalNotificationsplugin - The line of the calling code where
LocalNotifications.listChannels()was called
This makes it rather hard to find where certain errors are originating from.
Platform(s)
- Android
- iOS
Preferred Solution
There are multiple solutions I can think of:
- Include the location of the calling code in the stack trace
- Update the default error message of "UNIMPLEMENTED" errors to include the plugin and method name (and optionally the platform)
- Include plugin and method names as additional properties on the error object
Include the location of the calling code in the stack trace
This would be the ideal solution.
If the line that is calling the problematic plugin method, e.g. the line where LocalNotifications.listChannels() gets called, was included in the stack trace, then it would be obvious where an error is originating from.
I'm not sure if this can be achieved though.
Update the default error message
Instead of having a default error message of Error: not implemented, the default message could include the name of the plugin,
the name of the plugin method, and optionally the platform.
So for example, the message could then be Error: LocalNotifications.listChannels is not implemented on iOS.
This isn't a great solution though, as it would require a breaking change. And it also wouldn't work if a plugin method provides a custom error message, like here for example.
Include plugin and method names as additional properties on the error object
This seems like a straightforward solution to implement. It wouldn't be quite as user-friendly as the other approaches though, as some work is required by the developer that is using Capacitor to make this useful.
The approach here would be to add pluginId and methodName to the error object. This requires a small change in native-bridge.js, here for iOS, and here for Android. Essentially:
// looks like we've got a stored call
if (result.error) {
// ensure stacktraces by copying error properties to an Error
- result.error = Object.keys(result.error).reduce((err, key) => {
+ const newError = Object.keys(result.error).reduce((err, key) => {
// use any type to avoid importing util and compiling most of .ts files
err[key] = result.error[key];
return err;
}, new cap.Exception(''));
+
+ newError["pluginId"] = result.pluginId
+ newError["methodName"] = result.methodName
+
+ result.error = newError
}
As a user of Capacitor, one could then have a global error handler along the lines of:
window.addEventListener('unhandledrejection', err => {
if (err.reason?.code === 'UNIMPLEMENTED'
&& err.reason?.pluginId
&& err.reason?.methodName
) {
// Get platform: 'android', 'ios', or 'web'.
// Can be done for example using the `@capacitor/device` plugin.
const platform = 'xxx'
// Do something else with the error here. E.g. send it to Sentry, etc.
console.log(`${err.reason.pluginId}.${err.reason.methodName} is not implemented on platform ${platform}.`)
}
})
And this would print for example:
LocalNotifications.listChannels is not implemented on platform xxx.
Not as good as having the line where the problematic method is called mentioned in the stack trace, but this would make it easy enough to find were an error gets triggered.
Alternatives
I haven't found any solution that doesn't involve making changes to internal Capacitor code.
Additional Context
Minimal sample application: https://github.com/Dennitz/capacitor-error-reporting-example
The application includes examples of UNIMPLEMENTED errors for both iOS and Android.
The example for iOS calls LocalNotifications.listChannels, which isn't implemented on iOS.
And the Android example calls Camera.getLimitedLibraryPhotos, which isn't implemented on Android.
When testing the iOS example, please comment out the Android example, i.e. make sure these lines are commented out.
Vice versa, when testing the Android example, make sure these lines are commented out.
In both examples, a plugin method is called that isn't implemented on the platform. The error is then caught, and logged to the console.
There it can be seen that the error and its stack trace don't make it visible what plugin and plugin method are causing the error.
Example from iOS:
With the top item of the stack trace linking here (which doesn't reveal anything either):
Example from Android:
- Lenguaje dominante
- TypeScript
- Estrellas
- 17.1k
- Forks
- 1.3k
- Merge medio
- 1 d 22 h
- PR fusionados (30 d)
- 26
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ionic-team/capacitor
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ionic-team/capacitor#8759 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updatedPosiblemente ocupada @MateStrysewske la tomó hace 71 días. Abiertotriage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
ionic-team/capacitor#8616 ·
Los mantenedores suelen responder en 1 día
-
help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ionic-team/capacitor#8574 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)Posiblemente ocupada @kttalley la tomó hace 62 días. Abiertotriage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ionic-team/capacitor#8530 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
fix(android): remove unchecked Java compilation warningsPosiblemente ocupada @Ajamuar la tomó hace 15 días. Abiertotriage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ionic-team/capacitor#8529 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de ionic-team/capacitor
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
prio:low scope:world
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
OliverRomhagen/vrigstad-joyride#849 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
genfeedai/genfeed.ai#11916 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
erkamyaman/rust-anything#1153 ·
Los mantenedores suelen responder en 1 día
-
The Phase 5 report says 0.3.0 waits for the live checkPosiblemente ocupada @fzn0x la tomó hoy. Abiertodocumentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día