Catch settings file loading fail;
Standarize exit error codes
This commit is contained in:
1 parent
5ba2fbe567
commit
12fdf7ab96
2 files changed
+23
-4
No files matched your search
@@ -31,7 +31,7 @@ class Parser(argparse.ArgumentParser):
|
|||||||
|
|
||||||
def exit(self, status: int = 0, message: str | None = None) -> NoReturn:
|
def exit(self, status: int = 0, message: str | None = None) -> NoReturn:
|
||||||
try:
|
try:
|
||||||
super().exit(status, message)
|
super().exit(status, message) # sys.exit(2)
|
||||||
finally:
|
finally:
|
||||||
messagebox.showerror("Argument Parser Error", self._message.getvalue())
|
messagebox.showerror("Argument Parser Error", self._message.getvalue())
|
||||||
|
|
||||||
@@ -98,11 +98,18 @@ parser.add_argument(
|
|||||||
parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true", help=argparse.SUPPRESS)
|
parser.add_argument("--debug-ws", dest="_debug_ws", action="store_true", help=argparse.SUPPRESS)
|
||||||
parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true", help=argparse.SUPPRESS)
|
parser.add_argument("--debug-gql", dest="_debug_gql", action="store_true", help=argparse.SUPPRESS)
|
||||||
args = parser.parse_args(namespace=ParsedArgs())
|
args = parser.parse_args(namespace=ParsedArgs())
|
||||||
|
# load settings
|
||||||
|
try:
|
||||||
|
settings = Settings(args)
|
||||||
|
except Exception:
|
||||||
|
messagebox.showerror(
|
||||||
|
"Settings error",
|
||||||
|
f"There was an error while loading the settings file:\n\n{traceback.format_exc()}"
|
||||||
|
)
|
||||||
|
sys.exit(4)
|
||||||
# dummy window isn't needed anymore
|
# dummy window isn't needed anymore
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
# load settings
|
|
||||||
settings = Settings(args)
|
|
||||||
# check if we're not already running
|
# check if we're not already running
|
||||||
try:
|
try:
|
||||||
exists = ctypes.windll.user32.FindWindowW(None, WINDOW_TITLE)
|
exists = ctypes.windll.user32.FindWindowW(None, WINDOW_TITLE)
|
||||||
@@ -111,7 +118,7 @@ except AttributeError:
|
|||||||
exists = False
|
exists = False
|
||||||
if exists and not settings.no_run_check:
|
if exists and not settings.no_run_check:
|
||||||
# already running - exit
|
# already running - exit
|
||||||
sys.exit()
|
sys.exit(3)
|
||||||
|
|
||||||
# handle logging stuff
|
# handle logging stuff
|
||||||
if settings.logging_level > logging.DEBUG:
|
if settings.logging_level > logging.DEBUG:
|
||||||
@@ -128,6 +135,7 @@ logging.getLogger("TwitchDrops.gql").setLevel(settings.debug_gql)
|
|||||||
logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
||||||
|
|
||||||
# client run
|
# client run
|
||||||
|
exit_status = 0
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
client = Twitch(settings)
|
client = Twitch(settings)
|
||||||
signal.signal(signal.SIGINT, lambda *_: client.close())
|
signal.signal(signal.SIGINT, lambda *_: client.close())
|
||||||
@@ -135,11 +143,13 @@ signal.signal(signal.SIGTERM, lambda *_: client.close())
|
|||||||
try:
|
try:
|
||||||
loop.run_until_complete(client.run())
|
loop.run_until_complete(client.run())
|
||||||
except CaptchaRequired:
|
except CaptchaRequired:
|
||||||
|
exit_status = 1
|
||||||
msg = "Your login attempt was denied by CAPTCHA.\nPlease try again in +12 hours."
|
msg = "Your login attempt was denied by CAPTCHA.\nPlease try again in +12 hours."
|
||||||
logger.exception(msg)
|
logger.exception(msg)
|
||||||
client.prevent_close()
|
client.prevent_close()
|
||||||
client.print(msg)
|
client.print(msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
exit_status = 1
|
||||||
msg = "Fatal error encountered:\n"
|
msg = "Fatal error encountered:\n"
|
||||||
logger.exception(msg)
|
logger.exception(msg)
|
||||||
client.prevent_close()
|
client.prevent_close()
|
||||||
@@ -158,3 +168,4 @@ client.gui.stop()
|
|||||||
client.gui.close_window()
|
client.gui.close_window()
|
||||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||||
loop.close()
|
loop.close()
|
||||||
|
sys.exit(exit_status)
|
||||||
@@ -16,3 +16,11 @@ Available command line arguments:
|
|||||||
Show application version information
|
Show application version information
|
||||||
|
|
||||||
Note: Additional settings are available within the application GUI.
|
Note: Additional settings are available within the application GUI.
|
||||||
|
|
||||||
|
Exit codes:
|
||||||
|
|
||||||
|
• 0: Application exited successfully
|
||||||
|
• 1: Exit caused by the CAPTCHA or a Fatal Exception
|
||||||
|
• 2: Incorrect command line arguments
|
||||||
|
• 3: Application already running
|
||||||
|
• 4: Loading of the settings file failed
|
||||||
Reference in new issue
Block a user