node-red-nodes icon indicating copy to clipboard operation
node-red-nodes copied to clipboard

Add error messages when `/dev/input` fails to open

Open pacohope opened this issue 2 years ago • 1 comments

Which node are you reporting an issue on?

node-red-node-pi-gpio

What are the steps to reproduce?

  1. Install node-red on a raspberry pi running raspberry pi OS (Debian 11)
  2. Make sure the user running node-red is NOT a member of the input group in /etc/group
  3. Create a flow with an rpi-keyboard node
  4. Deploy the flow. Note that the rpi-keyboard node will vascillate between "OK" and "Stopped"
  5. Look in the node red logs (e.g., run node-red-log) and look for information about what is wrong
  6. Find none. :)

What happens?

There is no error logged that I could find in this circumstance. For background, you can see my discord post about it, too.

What do you expect to happen?

It would be nice if there was a "Failed to open keyboard: permission denied" or similar log message.

I looked at the code, and it seems like lines 185 and 208 of nrgpio.py might be the right place. I'd be happy to submit a PR with a few except calls in there to handle the failed permissions and post error messages. It would be my first contribution, so I wanted to ask about whether (a) this is the right place, and (b) won't this flood the logs with messages over and over, every time it tries to initialise the keyboard or mouse? So is there something I should do to throttle it or limit the amount of logging it does?

If someone wants to answer the questions to make sure I have the problem correctly scoped and whether I'm right about the solution, I will gladly work up and contribute a PR to fix it.

Please tell us about your environment:

  • [x] Node-RED version: 3.0.2
  • [x] node.js version: v16.20.0
  • [x] npm version: 9.6.7
  • [x] Platform/OS: Linux raspberrypi 6.1.21-v8+
  • [x] Browser: Firefox usually

pacohope avatar Jun 01 '23 13:06 pacohope

Hi yes - a pull request would be most welcome ! so a) yes - this is fine ! b) possibly yes - you could add a delay so it only retries every 10-15 secs - which would off course still flood the log - but more slowly... or you could hold the error in a flag variable - and if you see it again then don't report it. (and clear the variable on success of course) - that way it would only be reported once which would cleaner.

dceejay avatar Jun 01 '23 17:06 dceejay