From 088a69d9d912caccc1b238b1602e2066f0a50b55 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 9 Dec 2019 16:23:09 -0800 Subject: [PATCH] catching grpc error on setup, displaying error dialog and exiting app --- coretk/coretk/app.py | 3 +++ coretk/coretk/coreclient.py | 48 ++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/coretk/coretk/app.py b/coretk/coretk/app.py index 2dd2c5ca..4d51cd1e 100644 --- a/coretk/coretk/app.py +++ b/coretk/coretk/app.py @@ -98,6 +98,9 @@ class Application(tk.Frame): def save_config(self): appconfig.save(self.guiconfig) + def close(self): + self.master.destroy() + if __name__ == "__main__": log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s" diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 44e4ee99..5c728477 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -6,6 +6,9 @@ import logging import os import time from pathlib import Path +from tkinter import messagebox + +import grpc from core.api.grpc import client, core_pb2 from coretk import appconfig @@ -386,28 +389,35 @@ class CoreClient: :return: existing sessions """ - self.client.connect() + try: + self.client.connect() - # get service information - response = self.client.get_services() - for service in response.services: - group_services = self.services.setdefault(service.group, set()) - group_services.add(service.name) + # get service information + response = self.client.get_services() + for service in response.services: + group_services = self.services.setdefault(service.group, set()) + group_services.add(service.name) - # if there are no sessions, create a new session, else join a session - response = self.client.get_sessions() - logging.info("current sessions: %s", response) - sessions = response.sessions - if len(sessions) == 0: - self.create_new_session() - else: - dialog = SessionsDialog(self.app, self.app) - dialog.show() + # if there are no sessions, create a new session, else join a session + response = self.client.get_sessions() + logging.info("current sessions: %s", response) + sessions = response.sessions + if len(sessions) == 0: + self.create_new_session() + else: + dialog = SessionsDialog(self.app, self.app) + dialog.show() - response = self.client.get_service_defaults(self.session_id) - self.default_services = { - x.node_type: set(x.services) for x in response.defaults - } + response = self.client.get_service_defaults(self.session_id) + self.default_services = { + x.node_type: set(x.services) for x in response.defaults + } + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNAVAILABLE: + messagebox.showerror("Server Error", e.details()) + else: + messagebox.showerror("GRPC Error", e.details()) + self.app.close() def get_session_state(self): response = self.client.get_session(self.session_id)