I am trying to show user friendly error messages to the user when they try to connect to a WiFi network. If they type in the SSID incorrect, I get an error that has a code 10. If the user types the SSID correct, but provides the wrong secret, no code is given.
I would expect the errors to all follow the same format, providing a code or a way to decipher if its an unknown SSID or bad password via code.
Current Behavior
Currently, bad SSIDs report an error with killed, code, signal and cmd:
Error: No network with SSID 'RC Engineering 2.4GH' found.
at ChildProcess.exithandler (child_process.js:308:12)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
killed: false,
code: 10,
signal: null,
cmd: 'nmcli -w 10 device wifi connect RC Engineering 2.4GH password dsf ifname wlan0'
}
Good SSID but bad password reports no error code:
Error: Connection activation failed: (7) Secrets were required, but not provided.
at /var/www/node_modules/node-wifi/src/linux-connect.js:23:13
at ChildProcess.exithandler (child_process.js:299:7)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
Another example where a code is given is invalid permissions:
Error: Command failed: nmcli -w 10 device wifi connect RC Engineering 2.4GHz password dsf ifname wlan0
Error: Failed to add/activate new connection: Not authorized to control networking.
at ChildProcess.exithandler (child_process.js:308:12)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:443:11)
at Socket.emit (events.js:314:20)
at Pipe.<anonymous> (net.js:676:12) {
killed: false,
code: 4,
signal: null,
cmd: 'nmcli -w 10 device wifi connect RC Engineering 2.4GHz password dsf ifname wlan0'
}
Affected features
[X] node API
[ ] cli
Possible Solution
Add consistent formatting to any thrown errors - custom error class?
I could do a string search for something like "secrets were required" but that could easily be broken. Having a code that wont change would be best.
Steps to Reproduce (for bugs)
Call the .connect function with a bad SSID
Call the .connect function with a good SSID but bad password
Note that error messages are different format.
Context
This would help developers better be able to integrate node-wifi into their app by allowing them to more easily code what to do depending on the outcome of a task. Theres already a code for the "no network" error, and I'm sure theres other scenarios where an error is thrown that would be useful to have a list of possible error codes.
I am trying to show user friendly error messages to the user when they try to connect to a WiFi network. If they type in the SSID incorrect, I get an error that has a code 10. If the user types the SSID correct, but provides the wrong secret, no code is given.
Expected Behavior
I would expect the errors to all follow the same format, providing a code or a way to decipher if its an unknown SSID or bad password via code.
Current Behavior
Currently, bad SSIDs report an error with killed, code, signal and cmd:
Good SSID but bad password reports no error code:
Another example where a code is given is invalid permissions:
Affected features
[X] node API
[ ] cli
Possible Solution
Add consistent formatting to any thrown errors - custom error class?
I could do a string search for something like "secrets were required" but that could easily be broken. Having a code that wont change would be best.
Steps to Reproduce (for bugs)
Context
This would help developers better be able to integrate node-wifi into their app by allowing them to more easily code what to do depending on the outcome of a task. Theres already a code for the "no network" error, and I'm sure theres other scenarios where an error is thrown that would be useful to have a list of possible error codes.
Your Environment