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')
LOCATIONS_RE = re.compile(r'^([+-]|.*, [+-]|.*:[+-])')
class ParseError(Exception):
"""Generic error for parsing."""
class StringIOMode(StringIO):
"""
StringIO with mode attribute to make ttkit happy.
......
......@@ -33,7 +33,7 @@ import sys
import time
import fnmatch
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.filelock import FileLock
from weblate.trans.fields import RegexField
......@@ -705,7 +705,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
ret = self.update_branch(request, method=method)
# create translation objects for all files
self.create_translations(request=request)
try:
self.create_translations(request=request)
except ParseError:
ret = False
# Push after possible merge
if (self.repo_needs_push() and
......@@ -1409,7 +1412,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
str(exc),
u''.join(traceback.format_stack()),
)
raise
raise ParseError(str(exc))
return self._template_store
......
......@@ -36,7 +36,7 @@ from datetime import datetime, timedelta
from weblate import appsettings
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.models.unit import Unit
from weblate.trans.models.unitdata import Suggestion
......@@ -445,13 +445,15 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
if self._store is None:
try:
self._store = self.load_store()
except ParseError:
raise
except Exception as exc:
report_error(exc, sys.exc_info())
self.subproject.notify_merge_failure(
str(exc),
u''.join(traceback.format_stack()),
)
raise
raise ParseError(str(exc))
return self._store
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