Commit ddc32ebf authored by Michal Čihař's avatar Michal Čihař

Attempt to better handle parse errors

We let the update fail and keep the repository as is. This should work
fine for most cases, but users won't be able to update the translations.

Fixes #814
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 96e5c6e7
...@@ -48,6 +48,10 @@ FLAGS_RE = re.compile(r'\b[-\w]+\b') ...@@ -48,6 +48,10 @@ FLAGS_RE = re.compile(r'\b[-\w]+\b')
LOCATIONS_RE = re.compile(r'^([+-]|.*, [+-]|.*:[+-])') LOCATIONS_RE = re.compile(r'^([+-]|.*, [+-]|.*:[+-])')
class ParseError(Exception):
"""Generic error for parsing."""
class StringIOMode(StringIO): class StringIOMode(StringIO):
""" """
StringIO with mode attribute to make ttkit happy. StringIO with mode attribute to make ttkit happy.
......
...@@ -33,7 +33,7 @@ import sys ...@@ -33,7 +33,7 @@ import sys
import time import time
import fnmatch import fnmatch
import re import re
from weblate.trans.formats import FILE_FORMAT_CHOICES, FILE_FORMATS from weblate.trans.formats import FILE_FORMAT_CHOICES, FILE_FORMATS, ParseError
from weblate.trans.mixins import PercentMixin, URLMixin, PathMixin from weblate.trans.mixins import PercentMixin, URLMixin, PathMixin
from weblate.trans.filelock import FileLock from weblate.trans.filelock import FileLock
from weblate.trans.fields import RegexField from weblate.trans.fields import RegexField
...@@ -705,7 +705,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -705,7 +705,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
ret = self.update_branch(request, method=method) ret = self.update_branch(request, method=method)
# create translation objects for all files # create translation objects for all files
try:
self.create_translations(request=request) self.create_translations(request=request)
except ParseError:
ret = False
# Push after possible merge # Push after possible merge
if (self.repo_needs_push() and if (self.repo_needs_push() and
...@@ -1409,7 +1412,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin): ...@@ -1409,7 +1412,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
str(exc), str(exc),
u''.join(traceback.format_stack()), u''.join(traceback.format_stack()),
) )
raise raise ParseError(str(exc))
return self._template_store return self._template_store
......
...@@ -36,7 +36,7 @@ from datetime import datetime, timedelta ...@@ -36,7 +36,7 @@ from datetime import datetime, timedelta
from weblate import appsettings from weblate import appsettings
from weblate.lang.models import Language from weblate.lang.models import Language
from weblate.trans.formats import AutoFormat, StringIOMode from weblate.trans.formats import AutoFormat, StringIOMode, ParseError
from weblate.trans.checks import CHECKS from weblate.trans.checks import CHECKS
from weblate.trans.models.unit import Unit from weblate.trans.models.unit import Unit
from weblate.trans.models.unitdata import Suggestion from weblate.trans.models.unitdata import Suggestion
...@@ -445,13 +445,15 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -445,13 +445,15 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
if self._store is None: if self._store is None:
try: try:
self._store = self.load_store() self._store = self.load_store()
except ParseError:
raise
except Exception as exc: except Exception as exc:
report_error(exc, sys.exc_info()) report_error(exc, sys.exc_info())
self.subproject.notify_merge_failure( self.subproject.notify_merge_failure(
str(exc), str(exc),
u''.join(traceback.format_stack()), u''.join(traceback.format_stack()),
) )
raise raise ParseError(str(exc))
return self._store return self._store
def check_sync(self, force=False, request=None, change=None): def check_sync(self, force=False, request=None, change=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment