From be5122f3088ce2c3ade4707b7718810117e1d246 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Mon, 12 Jun 2023 13:10:56 +0200
Subject: [PATCH] add try catch to git repo creation

---
 .../management/commands/advance_git_repos.py  | 54 ++++++++++++++-----
 1 file changed, 41 insertions(+), 13 deletions(-)

diff --git a/scipost_django/production/management/commands/advance_git_repos.py b/scipost_django/production/management/commands/advance_git_repos.py
index f9b8de2c5..054723dc5 100644
--- a/scipost_django/production/management/commands/advance_git_repos.py
+++ b/scipost_django/production/management/commands/advance_git_repos.py
@@ -475,28 +475,56 @@ class Command(BaseCommand):
         # Create the repos
         repos_to_be_created = repos.filter(status=PROOFS_REPO_UNINITIALIZED)
         for repo in repos_to_be_created:
-            self._create_git_repo(repo)
-            repo.status = PROOFS_REPO_CREATED
-            repo.save()
+            try:
+                self._create_git_repo(repo)
+                repo.status = PROOFS_REPO_CREATED
+                repo.save()
+            except Exception as e:
+                self.stdout.write(
+                    self.style.ERROR(
+                        f"Could not create the git repo for {repo.git_path}, error: {e}"
+                    )
+                )
 
         # Copy the pure templates
         repos_to_be_templated = repos.filter(status=PROOFS_REPO_CREATED)
         for repo in repos_to_be_templated:
-            self._copy_pure_templates(repo)
-            repo.status = PROOFS_REPO_TEMPLATE_ONLY
-            repo.save()
+            try:
+                self._copy_pure_templates(repo)
+                repo.status = PROOFS_REPO_TEMPLATE_ONLY
+                repo.save()
+            except Exception as e:
+                self.stdout.write(
+                    self.style.ERROR(
+                        f"Could not copy the pure templates to {repo.git_path}, error: {e}"
+                    )
+                )
 
         # Format the skeleton files
         repos_to_be_formatted = repos.filter(status=PROOFS_REPO_TEMPLATE_ONLY)
         for repo in repos_to_be_formatted:
-            self._format_skeleton(repo)
-            repo.status = PROOFS_REPO_TEMPLATE_FORMATTED
-            repo.save()
+            try:
+                self._format_skeleton(repo)
+                repo.status = PROOFS_REPO_TEMPLATE_FORMATTED
+                repo.save()
+            except Exception as e:
+                self.stdout.write(
+                    self.style.ERROR(
+                        f"Could not format the skeleton of {repo.git_path}, error: {e}"
+                    )
+                )
 
         # Copy the arXiv source files
         repos_to_be_copied = repos.filter(status=PROOFS_REPO_TEMPLATE_FORMATTED)
         for repo in repos_to_be_copied:
-            if "arxiv.org" in repo.stream.submission.preprint.url:
-                self._copy_arxiv_source_files(repo)
-                repo.status = PROOFS_REPO_PRODUCTION_READY
-                repo.save()
+            try:
+                if "arxiv.org" in repo.stream.submission.preprint.url:
+                    self._copy_arxiv_source_files(repo)
+                    repo.status = PROOFS_REPO_PRODUCTION_READY
+                    repo.save()
+            except Exception as e:
+                self.stdout.write(
+                    self.style.ERROR(
+                        f"Could not copy the arXiv source files to {repo.git_path}, error: {e}"
+                    )
+                )
-- 
GitLab