From be63e720d965de30835e62a92c3e1500cfd7dc5b Mon Sep 17 00:00:00 2001 From: Max Wittig Date: Tue, 23 Apr 2019 07:52:34 +0200 Subject: [PATCH] fix: except all GitLab errors --- gitlab_languages.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gitlab_languages.py b/gitlab_languages.py index fc380f7..f0d4230 100644 --- a/gitlab_languages.py +++ b/gitlab_languages.py @@ -30,6 +30,16 @@ worker_count = multiprocessing.cpu_count() * 2 +def error_wrapper(gen): + while True: + try: + yield next(gen) + except StopIteration: + return + except (GitlabGetError, GitlabHttpError): + pass + + def memoize(func): @functools.wraps(func) def wrapper_decorator(*args, **kwargs): @@ -210,11 +220,11 @@ def scan_group_projects(self, group_ids): self.groups_scanned += 1 projects = self.gl_helper.get_group_projects(group) with ThreadPoolExecutor(max_workers=worker_count) as executor: - for project in projects: + for project in error_wrapper(projects): try: project = self.gl.projects.get(project.id, simple=True) executor.submit(self.scan, project) - except Exception: + except (GitlabGetError, GitlabHttpError): continue def write_metrics(self, path=Path.cwd() / "metrics.txt"): @@ -244,11 +254,8 @@ def scan_projects(self, limit=None, args=None): logger.info(f"with additional arguments {args}") with ThreadPoolExecutor(max_workers=worker_count) as executor: - for project in projects: - try: - executor.submit(self.scan, project) - except Exception: - continue + for project in error_wrapper(projects): + executor.submit(self.scan, project) def check_env_variables():