luludotdev/hwid

UnhandledPromiseRejectionWarning causes crash on Linux

Opened this issue · 2 comments

This module casues a UnhandledPromiseRejectionWarning exception when running on Linux (CentOS in this case).

Error: Command failed: cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null

Running the command manually in a shell results in a proper output.
I am running on Nodejs v14.16.0. If you'd like I can take a look.

Root cause is one of the two files does not exist (on my CentOS machine it's the dbus/machine-id file). This causes an exit code of 1 instead of the expected 0. This in turns means that the promise for execa will be rejected and throw an exception - even though with exit code 1 the expected result is still returned.

In my opinion, when executing the shell command, it should be surrounded by try/catch and on exception the output length should be checked. If the output length is zero, in that case the exception should be re-thrown because it means something else is going on but as long as there's output it's an acceptable hwid. Alternatively you can also just check for 32 characters because I believe machine-id should always give you a UUID which is 32 characters long.

Again, please let me know if you want me to take a look at the source, I'd be happy to submit a PR!

possibly fixed in 0.5.0