From 1333c2dff87c6294d3db082c4884a2e764da134a Mon Sep 17 00:00:00 2001 From: Reza Rahemtola Date: Fri, 20 Oct 2023 00:03:13 +0200 Subject: [PATCH] fix(workers/google): Unsafe exception catching refactored --- backend/workers/google/src/classrooms/create_course.py | 4 ++-- backend/workers/google/src/contacts/create_contact.py | 4 ++-- backend/workers/google/src/docs/create_document.py | 4 ++-- backend/workers/google/src/forms/create_form.py | 4 ++-- backend/workers/google/src/gmail/create_draft.py | 4 ++-- backend/workers/google/src/gmail/send_email.py | 4 ++-- backend/workers/google/src/gmail/update_signature.py | 9 ++++----- backend/workers/google/src/slides/create_slide.py | 4 ++-- .../google/src/spreadsheets/create_spreadsheet.py | 4 ++-- backend/workers/google/src/youtube/create_comment.py | 5 ++--- 10 files changed, 22 insertions(+), 24 deletions(-) diff --git a/backend/workers/google/src/classrooms/create_course.py b/backend/workers/google/src/classrooms/create_course.py index bc3caa32..09b49e6b 100644 --- a/backend/workers/google/src/classrooms/create_course.py +++ b/backend/workers/google/src/classrooms/create_course.py @@ -48,8 +48,8 @@ def create_course(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/contacts/create_contact.py b/backend/workers/google/src/contacts/create_contact.py index 1994f198..221a9fbd 100644 --- a/backend/workers/google/src/contacts/create_contact.py +++ b/backend/workers/google/src/contacts/create_contact.py @@ -50,8 +50,8 @@ def create_contact(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/docs/create_document.py b/backend/workers/google/src/docs/create_document.py index b7c4658e..6ac74653 100644 --- a/backend/workers/google/src/docs/create_document.py +++ b/backend/workers/google/src/docs/create_document.py @@ -45,8 +45,8 @@ def create_document(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/forms/create_form.py b/backend/workers/google/src/forms/create_form.py index 485531da..a8d9ed49 100644 --- a/backend/workers/google/src/forms/create_form.py +++ b/backend/workers/google/src/forms/create_form.py @@ -47,8 +47,8 @@ def create_form(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/gmail/create_draft.py b/backend/workers/google/src/gmail/create_draft.py index 86c0992d..67147464 100644 --- a/backend/workers/google/src/gmail/create_draft.py +++ b/backend/workers/google/src/gmail/create_draft.py @@ -55,8 +55,8 @@ def create_draft(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/gmail/send_email.py b/backend/workers/google/src/gmail/send_email.py index dda9fd31..7c62d32f 100644 --- a/backend/workers/google/src/gmail/send_email.py +++ b/backend/workers/google/src/gmail/send_email.py @@ -55,8 +55,8 @@ def send_email(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/gmail/update_signature.py b/backend/workers/google/src/gmail/update_signature.py index b6a79d6b..595da3d9 100644 --- a/backend/workers/google/src/gmail/update_signature.py +++ b/backend/workers/google/src/gmail/update_signature.py @@ -56,11 +56,10 @@ def update_signature(): except RefreshError as error: with grpc.insecure_channel(target) as channel: - AreaBackServiceStub(channel).OnError(JobError(identifier=identifier, error=str(error), isAuthError=True)) + AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( - JobError(identifier=identifier, error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) + raise e diff --git a/backend/workers/google/src/slides/create_slide.py b/backend/workers/google/src/slides/create_slide.py index 8d830cc6..6c6cf4be 100644 --- a/backend/workers/google/src/slides/create_slide.py +++ b/backend/workers/google/src/slides/create_slide.py @@ -46,8 +46,8 @@ def create_slide(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/spreadsheets/create_spreadsheet.py b/backend/workers/google/src/spreadsheets/create_spreadsheet.py index 51d1be8a..c543868b 100644 --- a/backend/workers/google/src/spreadsheets/create_spreadsheet.py +++ b/backend/workers/google/src/spreadsheets/create_spreadsheet.py @@ -47,8 +47,8 @@ def create_spreadsheet(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e diff --git a/backend/workers/google/src/youtube/create_comment.py b/backend/workers/google/src/youtube/create_comment.py index 81a71a8d..e0bf7601 100644 --- a/backend/workers/google/src/youtube/create_comment.py +++ b/backend/workers/google/src/youtube/create_comment.py @@ -54,9 +54,8 @@ def create_comment(): with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError(JobError(identifier=args["identifier"], error=str(error), isAuthError=True)) exit(1) - - except: + except Exception as e: with grpc.insecure_channel(target) as channel: AreaBackServiceStub(channel).OnError( JobError(identifier=args["identifier"], error=str(sys.exc_info()[0]), isAuthError=False)) - exit(1) + raise e