[damned-lies] Try to avoid crashing on checkout errors



commit d5eaff28c092ddf4f77f49220ea3e606139a727a
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Jan 6 22:48:00 2022 +0100

    Try to avoid crashing on checkout errors

 stats/models.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 6fe7b236..85f7f010 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -463,8 +463,16 @@ class Branch(models.Model):
     def update_stats(self, force, checkout=True, domain=None):
         """ Update statistics for all po files from the branch """
         with ModuleLock(self.module):
+            checkout_errors = []
             if checkout:
-                self.checkout()
+                try:
+                    self.checkout()
+                except OSError as err:
+                    if self._repo.exists():
+                        checkout_errors.append(("warn", f"Unable to update branch: {err}"))
+                    else:
+                        raise
+
             domains = [domain] if domain is not None else self.get_domains().values()
             string_frozen = self.has_string_frozen()
             for dom in domains:
@@ -475,7 +483,7 @@ class Branch(models.Model):
                     # Delete existing stats, if any
                     Statistics.objects.filter(branch=self, domain=dom).delete()
                     continue
-                errors = []
+                errors = checkout_errors.copy()
 
                 # 2. Pre-check, if available (e.g. intltool-update -m)
                 # **************************


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]