From 60404a13810dd5807ec6ab440d284c391f23bcb4 Mon Sep 17 00:00:00 2001 From: troido Date: Tue, 22 May 2018 19:09:47 +0200 Subject: client raises exceptions outside main curses wrapper --- asciifarm/client/start.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'asciifarm/client/start.py') diff --git a/asciifarm/client/start.py b/asciifarm/client/start.py index fef5d9e..0c247b5 100644 --- a/asciifarm/client/start.py +++ b/asciifarm/client/start.py @@ -23,6 +23,7 @@ def main(name, socketType, address, keybindings, characters, colours=False, logf print("ERROR: Could not connect to server.\nAre you sure that the server is running and that you're connecting to the right address?", file=sys.stderr) return + error = None closeMessage = None os.environ.setdefault("ESCDELAY", "25") @@ -34,10 +35,18 @@ def main(name, socketType, address, keybindings, characters, colours=False, logf client.start() except KeyboardInterrupt: client.close("^C caught, goodbye") + except Exception as e: + # throw the execption outside ncurses + # so the cleanup can happen first + nonlocal error + error = e nonlocal closeMessage closeMessage = client.closeMessage - + curses.wrapper(start) + if error is not None: + raise error + if closeMessage: print(closeMessage, file=sys.stderr) -- cgit