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

bug(callCordovaPlugin): Cannot read property 'apply' of undefined #1327

Closed
AmitMY opened this issue Apr 5, 2017 · 0 comments
Closed

bug(callCordovaPlugin): Cannot read property 'apply' of undefined #1327

AmitMY opened this issue Apr 5, 2017 · 0 comments

Comments

@AmitMY
Copy link
Contributor

AmitMY commented Apr 5, 2017

I get this error:

Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined
from time to time, on device.

It happens for many plugins, but this stack trace is specifically the Rollbar one.

I think it would be good to have a check before this line: https://github.com/driftyco/ionic-native/blob/9074362caea1a13923d818d6d9714bb6a254c435/src/%40ionic-native/core/plugin.ts#L130

Something like:

if(!pluginInstance) 
    throw new Error(`Plugin ${pluginName} has no instance`);
if(!pluginInstance[methodName]) 
    throw new Error(`Plugin ${pluginName} has no method ${methodName}`);

I think that in this case, as in many others, doing console.warn is not the best thing, as it limits the error handling capability. In my case, I use Rollbar, and thrown errors are reported to me for review.

Here is a full stack:

Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined
TypeError: Cannot read property 'apply' of undefined
at callCordovaPlugin (http://10.0.0.15:8100/build/main.js:70204:42)
at http://10.0.0.15:8100/build/main.js:70214:24
at http://10.0.0.15:8100/build/main.js:49329:17
at new t (http://10.0.0.15:8100/build/polyfills.js:3:17644)
at tryNativePromise (http://10.0.0.15:8100/build/main.js:49328:20)
at getPromise (http://10.0.0.15:8100/build/main.js:49336:12)
at wrapPromise (http://10.0.0.15:8100/build/main.js:70213:93)
at Rollbar. (http://10.0.0.15:8100/build/main.js:70332:20)
at Rollbar.value [as init] (http://10.0.0.15:8100/build/main.js:122748:125)
at http://10.0.0.15:8100/build/main.js:123032:31
at t.invoke (http://10.0.0.15:8100/build/polyfills.js:3:14529)
at Object.onInvoke (http://10.0.0.15:8100/build/main.js:4425:37)
at t.invoke (http://10.0.0.15:8100/build/polyfills.js:3:14469)
at n.run (http://10.0.0.15:8100/build/polyfills.js:3:9741)
at http://10.0.0.15:8100/build/polyfills.js:3:6774
1
File http://10.0.0.15:8100/build/main.js line 70204 col 42 in callCordovaPlugin
2
File http://10.0.0.15:8100/build/main.js line 70214 col 24 in [anonymous]
3
File http://10.0.0.15:8100/build/main.js line 49329 col 17 in [anonymous]
4
File http://10.0.0.15:8100/build/polyfills.js line 3 col 17644 in new t
5
File http://10.0.0.15:8100/build/main.js line 49328 col 20 in tryNativePromise
6
File http://10.0.0.15:8100/build/main.js line 49336 col 12 in getPromise
7
File http://10.0.0.15:8100/build/main.js line 70213 col 93 in wrapPromise
8
File http://10.0.0.15:8100/build/main.js line 70332 col 20 in Rollbar.
9
File http://10.0.0.15:8100/build/main.js line 122748 col 125 in Rollbar.value [as init]
10
File http://10.0.0.15:8100/build/main.js line 123032 col 31 in [anonymous]
11
File http://10.0.0.15:8100/build/polyfills.js line 3 col 14529 in t.invoke
12
File http://10.0.0.15:8100/build/main.js line 4425 col 37 in Object.onInvoke
13
File http://10.0.0.15:8100/build/polyfills.js line 3 col 14469 in t.invoke
14
File http://10.0.0.15:8100/build/polyfills.js line 3 col 9741 in n.run
15
File http://10.0.0.15:8100/build/polyfills.js line 3 col 6774 in [anonymous]
16
File http://10.0.0.15:8100/build/polyfills.js line 3 col 7133 in g
17
File http://10.0.0.15:8100/build/polyfills.js line 3 col 6251 in l
18
File http://10.0.0.15:8100/build/polyfills.js line 3 col 17670 in new t
19
File http://10.0.0.15:8100/build/main.js line 49328 col 20 in tryNativePromise
20
File http://10.0.0.15:8100/build/main.js line 49336 col 12 in getPromise
21
File http://10.0.0.15:8100/build/main.js line 70213 col 93 in wrapPromise
22
File http://10.0.0.15:8100/build/main.js line 70332 col 20 in Rollbar.
23
File http://10.0.0.15:8100/build/main.js line 122748 col 125 in Rollbar.value [as init]
24
File http://10.0.0.15:8100/build/main.js line 123032 col 31 in [anonymous]
25
File http://10.0.0.15:8100/build/polyfills.js line 3 col 14529 in t.invoke
26
File http://10.0.0.15:8100/build/main.js line 4425 col 37 in Object.onInvoke
27
File http://10.0.0.15:8100/build/polyfills.js line 3 col 14469 in t.invoke
28
File http://10.0.0.15:8100/build/polyfills.js line 3 col 9741 in n.run
29
File http://10.0.0.15:8100/build/polyfills.js line 3 col 6774 in [anonymous]
30
File http://10.0.0.15:8100/build/polyfills.js line 3 col 15213 in t.invokeTask

ihadeed pushed a commit that referenced this issue Apr 14, 2017
* fix(cordova-plugin): add check if method exists

For #1327

* fix(plugin): add typeof to undefined check
@AmitMY AmitMY closed this as completed Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant