Unhelpful error message when invoke target does not exist
Hi, extremely useful library, thank you very much. One problem, though:
If I do plugin.invoke("does.not.exist"), I get
TypeError: o is undefined
_isFunc http://localhost:3001/src/modules/plugin.js:20
invoke http://localhost:3001/src/modules/plugin.js:127
invoke http://localhost:3001/src/modules/plugin.js:125
// ...
Would it be possible to implement a more helpful error message that would indicate the problem?
Thank you.
@cboulanger Hi I am not able to reproduce the issue, what version of js-plugin, node/browser version are you using? Looks like invoke a property/method that does not exist in plugin system won't throw an error from my side, could you provide more details of sample code on codesandbox or stackblitz?
@hacker0limbo Thanks for looking into this. I am using a copy of js-plugin manually adapted so that I can import it as a module, which makes it hard to reproduce. Would it be possible to first release a ESM-version which I can do import jsplugin from "js-plugin"? Then I can build a test case to see if the problem is in my code or the module?
Thank you!
@cboulanger Hi, I am not the author of this library so probably not able to release a ESM-version of js-plugin. However, from my understanding you can just directly install it using npm install js-plugin and then import it like import plugin from 'js-plugin' or maybe const plugin = require('./plugin'). Considering you are using a copy of js-plugin, would it be possible to paste or upload the copy version of source code somewhere so that i can take a look at that?
Cheers!
@hacker0limbo Thanks - here is the code:
https://gist.github.com/cboulanger/72a4f7bc43659608ed430ebfe203c07b
it's been a while since I tried and failed to import the unmodified plugin.js - so I simply patched it. But maybe it works without a patch and I just wasn't doing it right.
@cboulanger Thanks for your quick response. I checked the code you provided and didn't see any difference from the latest version of js-plugin and your patch version of js-plugin, except that you just changed the export way from module.exports to export default, which is totally fine for me.
I am guessing(i know this might be wrong), according to the error stack you provided, could you do me a favor, change the source code of the patch version you are locally using at line 19 to line 21, the _isFunc method.
So the source code looks like this:
function _isFunc(o) {
return !!(o.constructor && o.call && o.apply);
}
This would probably throw the error, considering if o is not an object type, for example it is undefined or null, so could you please change it to this:
function _isFunc(o) {
return typeof o === 'function'
}
So in this case it will safely determine the o is a function even though o is undefined.
Lets see if this solves your problem.
Cheers!
Thanks so much! I cannot test it right now, but will and report here if it solves the problem.