sde1000 / quicktill

Figure out where all the money and stock went to
GNU General Public License v3.0
43 stars 8 forks source link

Unhelpful exception when printer server is down #278

Closed sde1000 closed 7 months ago

sde1000 commented 7 months ago

Even just checking whether a printer is available causes an exception if the print server isn't running:

2024-01-30 13:39:15,370 ERROR quicktill.till
  Exception caught at top level
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/quicktill/till.py", line 298, in run
    ui_ncurses.run()
  File "/usr/lib/python3/dist-packages/quicktill/ui_ncurses.py", line 433, in run
    curses.wrapper(_init)
  File "/usr/lib/python3.8/curses/__init__.py", line 105, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/lib/python3/dist-packages/quicktill/ui_ncurses.py", line 420, in _init
    tillconfig.mainloop.iterate()
  File "/usr/lib/python3/dist-packages/quicktill/event.py", line 105, in iterate
    key.data(mask)
  File "/usr/lib/python3/dist-packages/quicktill/event.py", line 62, in _ready
    self._doread()
  File "/usr/lib/python3/dist-packages/quicktill/ui_ncurses.py", line 386, in _curses_keyboard_input
    ui.handle_raw_keyboard_input(kbcodes[i])
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 108, in handle_raw_keyboard_input
    handle_keyboard_input(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 86, in handle_keyboard_input
    basicwin._focus.hotkeypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 307, in hotkeypress
    self.parent.hotkeypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 307, in hotkeypress
    self.parent.hotkeypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 307, in hotkeypress
    self.parent.hotkeypress(k)
  [Previous line repeated 1 more time]
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 405, in hotkeypress
    basicwin._focus.keypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 957, in keypress
    super().keypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 717, in keypress
    self.parent.keypress(k)
  File "/usr/lib/python3/dist-packages/quicktill/ui.py", line 1263, in keypress
    i[1](*i[2])
  File "/usr/lib/python3/dist-packages/quicktill/stock.py", line 354, in item_chosen
    self.numfield_enter()
  File "/usr/lib/python3/dist-packages/quicktill/stock.py", line 327, in numfield_enter
    self.func(item)
  File "/usr/lib/python3/dist-packages/quicktill/managestock.py", line 303, in <lambda>
    stock.stockpicker(lambda x: stock.reprint_stocklabel_choose_printer(x.id),
  File "/usr/lib/python3/dist-packages/quicktill/user.py", line 130, in permission_check
    return function(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/quicktill/stock.py", line 30, in reprint_stocklabel_choose_printer
    menu = [(f"Print label on {x}",
  File "/usr/lib/python3/dist-packages/quicktill/stock.py", line 30, in <listcomp>
    menu = [(f"Print label on {x}",
  File "/usr/lib/python3/dist-packages/quicktill/pdrivers.py", line 540, in __str__
    o = self.offline()
  File "/usr/lib/python3/dist-packages/quicktill/pdrivers.py", line 547, in offline
    conn = cups.Connection(**self._connect_kwargs)
RuntimeError: failed to connect to server

So cups.Connection() raises RuntimeError if it can't connect. This should be caught and turned into something more useful, especially in cupsprinter.offline()

sde1000 commented 7 months ago

Implemented in 69f311ee2d081d445ae89de4ca1e69fe96af2b2e