mymonero / mymonero-core-js

The JS library containing the Monero crypto plus lightwallet functions behind the official MyMonero apps
BSD 3-Clause "New" or "Revised" License
101 stars 103 forks source link

Thrown Error not clear. #87

Closed babel5405 closed 5 years ago

babel5405 commented 5 years ago

The error thrown on line 79 of MyMoneroCoreBridge.js seems to attempt to explain a solution, but doesn't provide information as to how to resolve the issue.

throw "Unable to derive fullPath. Please pass locateFile() to bridge obj init."

What does "Please pass locateFile() to bridge obj init." mean? The issue causing it to be thrown comes from scriptDirectory being an empty string. The message provided at line 65 of the same file which console.warn'd at the same time also doesn't provide much in the way of useful information, because ${pathTo_cryptonoteUtilsDir} is undefined when it's used.

I should note that I'm attempting to use the library in an Electron App, I've tried using the library on both the render and main threads, and both used as a node module and compiled as if for a website with the compile scripts provided.

Versions: Node: 10.2.0 Electron: 3.0.9

paulshapiro commented 5 years ago

It means that your wasm / asm files are not in a standard / expected location. How are you attempting to bundle them?

babel5405 commented 5 years ago

I tired both importing it into node's module system, and package_browser_js in /bin.

I've done more testing since I encountered the issue though, and it appears to be that since I'm trying to use it with electron the element "window" exists, and it's playing havoc on the platform detection, causing it to think it's web instead of node, which causes the path to the modules to never be filled.

I'm going to keep testing and see if I can come up with with a good solution, but un-minifying MyMoneroCoreCpp_WASM.js and hacking it so the platform is node instead of web fixes the problem and causes it to start working again. I don't think the source for that file is part of this repo though correct?

babel5405 commented 5 years ago

After some more testing it appears that bringing the app into the main thread via a require() works correctly, and the errors only occur when trying to bring it into the render thread which makes sense.

The reason I couldn't get it to work in either appears to be the fault of a incompatibility with mymonero-core-js and electron-updater when debugging. Specifically portions of the error handling where mymonero-core-js takes over all un-handled exceptions (MyMoneroCoreCpp_WASM.js). I added a check to ensure auto-updater wasn't running in dev mode and it resolved the issue.

The reason this became an issue appears to be because electron-updater handles the error it generates and prevents it from being displayed or stopping the app, but somehow the error handling in core catches it before than can happen and shuts every thing down after dumping a stacktrace.

paulshapiro commented 5 years ago

Here, have a look at this. This is how we use MyMoneroCoreBridge (from the renderer process) in mymonero-app-js. We use IPC to talk to the main process.

https://github.com/mymonero/mymonero-app-js/blob/e2e85873c68df78449f814696883d4ff6cd5e1b7/local_modules/MoneroUtils/monero_utils.electron.web.js

which talks to

https://github.com/mymonero/mymonero-app-js/blob/e2e85873c68df78449f814696883d4ff6cd5e1b7/local_modules/MoneroUtils/__IPCSafe_remote_monero_utils.electron.js

and we include it like this in the renderer process

require('../../MoneroUtils/monero_utils.electron.web')({}).then(function(monero_utils)
{
})
paulshapiro commented 5 years ago

@babel5405 I'm going to disable emscripten catching uncaughtExceptions in Node.JS with NODEJS_CATCH_EXIT=0. Thanks

paulshapiro commented 5 years ago

That's been pushed

babel5405 commented 5 years ago

Cool, that looks to be everything I encountered, and your answer on how you implemented in electron helped as well.