psyinfra / onyo

text-based inventory system on top of git
ISC License
3 stars 5 forks source link

Better error when failing to read from stdin #698

Closed bpoldrack closed 1 month ago

bpoldrack commented 1 month ago

When an onyo command is used non-interactively but didn't use --yes, we'd fail with something like this:

Update assets? (y/n) [Default: yes] ERROR: EOF when reading a line
DEBUG:onyo:Traceback (most recent call last):
  File "/home/ben/work/hacking/onyo/onyo/main.py", line 543, in main
    args.run(args)
  File "/home/ben/work/hacking/onyo/onyo/cli/set.py", line 109, in set
    onyo_set(inventory=inventory,
  File "/home/ben/work/hacking/onyo/onyo/lib/commands.py", line 83, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ben/work/hacking/onyo/onyo/lib/commands.py", line 1073, in onyo_set
    if ui.request_user_response("Update assets? (y/n) "):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ben/work/hacking/onyo/onyo/lib/ui.py", line 235, in request_user_response
    answer = input(question) or default  # empty answer (hit return) gives the default answer
             ^^^^^^^^^^^^^^^
EOFError: EOF when reading a line

^ That's with --debug ofc.

We should probably catch that and say something like Couldn't read user input.