espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 90 forks source link

CLI attempts to access UNIX socket on Windows #150

Closed matpratta closed 2 years ago

matpratta commented 2 years ago

Seems like the CLI (installed via npm i -g espruino) tries to access some UNIX socket in Windows, failing on any command:

espruino --no-ble
Espruino Command-line Tool 0.1.42
-----------------------------------

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: connect ENOENT /var/run/dbus/system_bus_socket
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
Emitted 'error' event on MessageBus instance at:
    at EventEmitter.<anonymous> (C:\Users\matpr\AppData\Roaming\npm\node_modules\espruino\node_modules\dbus-next\lib\bus.js:159:12)
    at EventEmitter.emit (node:events:390:28)
    at Socket.<anonymous> (C:\Users\matpr\AppData\Roaming\npm\node_modules\espruino\node_modules\dbus-next\lib\connection.js:102:10)
    at Socket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'connect',
  address: '/var/run/dbus/system_bus_socket'
}
gfwilliams commented 2 years ago

Thanks - I think this is probably what https://github.com/espruino/EspruinoTools/issues/148 was referring to (or one of the things??), but I was seriously struggling get any useful info out of the reporter.

How are you running this? Is it Node running inside WSL, or are you just running Node on its own?

It seems serial_node_ble.js is calling node-ble and even though it's inside a try...catch statement, node-ble is still causing an error via dbus. I'm kind of confused that dbus-next would even initialise to be honest.

I've just made a change (are you ok to try the version from GitHub?) and it's possible that it'll work for you now.

matpratta commented 2 years ago

Hi @gfwilliams!

Running with Node.js installed directly on Windows, not inside WSL or anything here. Your commits seem to have fixed the issue I was having regarding the system bus socket.

I still have an error that there's no compatible Bluetooth 4.0 device connected when not running with the argument --no-ble, which is a bit odd, but could be because I don't have any boards connected right now even with USB (without any board close right now)

The main problem on my issue seems to be fixed though!

gfwilliams commented 2 years ago

Excellent, thanks! I'll push an NPM release!

BLE on Windows with Node.js is a bit of a nightmare. I'd have hoped that winnus would work but it may not build on newer Node.js versions. If someone has a solution I'd love to implement it though.

ClintH commented 2 years ago

AFAIK this should have been fixed in 0.1.43? I'm getting roughly the same error on Windows, not using WSL.

CLI:

espruino --list

Error:

Espruino Command-line Tool 0.1.43
    at Socket.<anonymous> (C:\Users\ch\scoop\persist\nvm\nodejs\v17.3.1\node_modules\espruino\node_modules\dbus-next\lib\connection.js:102:10)
-----------------------------------

undefined:55
    } else throw err;
           ^

Error: connect ENOENT /var/run/dbus/system_bus_socket
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)Emitted 'error' event on MessageBus instance at:
    at EventEmitter.<anonymous> (C:\Users\ch\scoop\persist\nvm\nodejs\v17.3.1\node_modules\espruino\node_modules\dbus-next\lib\bus.js:159:12)    at EventEmitter.emit (node:events:390:28)
    at Socket.<anonymous> (C:\Users\ch\scoop\persist\nvm\nodejs\v17.3.1\node_modules\espruino\node_modules\dbus-next\lib\connection.js:102:10)
    at Socket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'connect',
  address: '/var/run/dbus/system_bus_socket'
}

Node.js v17.3.1
gfwilliams commented 2 years ago

It should have been fixed yes...

Do you get the error with espruino --list --no-ble ?

ClintH commented 2 years ago

I don't get the error, but I get:

Error: No Ports Found

It should, like the installed 0.74.1 Espruino IDE (Chrome App) find the Pico connected on COM6.

gfwilliams commented 2 years ago

And what does it say with '--verbose'? Have you had any success with EspruinoTools before? Because it may just be that for some reason the serialport module hasn't installed

ClintH commented 2 years ago

Yep, --verbose shows it's missing Acorn, serialport, winnus.

Haven't tried using it before. But I would expect that installing espruino with npm install -g espruino would install all dependencies?

gfwilliams commented 2 years ago

We try, and it should be installed: https://github.com/espruino/EspruinoTools/blob/master/package.json#L34

But if someone's not using the serial port there's no point in failing to install EspruinoTools because the serial port library won't install properly.

Maybe if you try npm install serialport you'll get to see whether there's some kind of error which shows why it wasn't installed?

ClintH commented 2 years ago

Thanks Gordon, I had to mess about getting the Windows build tools installed again for some reason. Now it works.

Because there are no warnings when installing espruino, it might be helpful if espruino spat out a warning if a module is missing, or some high-level error catching to give the hint to try running espruino with --verbose?

For what it's worth, the v10 series of serialport installed cleanly without having to mess with the build tools, presumably due to improved binary bundling and change in native interop.

gfwilliams commented 2 years ago

Ok, I've just moved to serialport 10 and added a note about using --verbose if not ports are found.

I've also removed node_ble because it's been nothing but trouble since it was added.

If you'd like to contribute some extra code to make it a bit easier to get started then that'd be great though - but bear in mind that sometimes people don't care about serial ports, and sometimes they don't care about bluetooth.

There is a system in there for reporting issues with modules (which the Web IDE uses if you open the connection and then go to status) so maybe that could be improved for Node.js specific modules and used with a --status argument