WebThingsIO / zwave-adapter

Z-Wave adapter add-on for WebThings Gateway
Mozilla Public License 2.0
15 stars 20 forks source link

Need to report a decent error if the user doesn't have permissions for a serial port #33

Open mrstegeman opened 6 years ago

mrstegeman commented 6 years ago

By default (under ubuntu) you need to be root or a member of the dialout group in order to open the serial port.

If the user doesn't have sufficient permissions then we should detect this and report a reasonable error.

Requires mozilla-iot/gateway#877

Swaagie commented 4 years ago

@mrstegeman The first (partial) fix for this is in systemd https://github.com/systemd/systemd/issues/14959#issuecomment-591971588. Just ran into the same issue a bit different. serialport uses udevadm info -e under the hood to list available ports. However udevadm didn't emit any errors and only exits with code 1. The second step here would be getting serialport to listen for the errors (or at minimum exit code 1 on finish) https://github.com/serialport/node-serialport/blob/258574260f312cdeb81bb265a437762f8e5e0ae4/packages/bindings/lib/linux-list.js#L43.

I'll open a PR against serialport to at rejecton exit code 1 as I'm unsure how fast different distro's will pickup on the improved systemd. From source code it seems that both darwin and w32 use async/await and should throw on error.

After serialport merges the PR, gateway should technically be able to reject based on errors.

Swaagie commented 4 years ago

https://github.com/serialport/node-serialport/pull/2046 is now a thing and list should reject with an error