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

Add hooks to new error reporting code

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 5f39a03d
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# #
import urllib2 import urllib2
import sys
import urllib import urllib
import hashlib import hashlib
import os.path import os.path
...@@ -31,6 +32,7 @@ from django.conf import settings ...@@ -31,6 +32,7 @@ from django.conf import settings
import weblate import weblate
from weblate import appsettings from weblate import appsettings
from weblate.trans.util import report_error
try: try:
import libravatar # pylint: disable=import-error import libravatar # pylint: disable=import-error
...@@ -127,6 +129,10 @@ def get_avatar_image(user, size): ...@@ -127,6 +129,10 @@ def get_avatar_image(user, size):
image = download_avatar_image(user, size) image = download_avatar_image(user, size)
cache.set(cache_key, image) cache.set(cache_key, image)
except IOError as error: except IOError as error:
report_error(
error, sys.exc_info(),
extra_data={'avatar': user.username}
)
weblate.logger.error( weblate.logger.error(
'Failed to fetch avatar for %s: %s', 'Failed to fetch avatar for %s: %s',
user.username, user.username,
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# #
import os import os
import sys
import binascii import binascii
from smtplib import SMTPException from smtplib import SMTPException
...@@ -39,6 +40,7 @@ from social.apps.django_app.default.models import UserSocialAuth ...@@ -39,6 +40,7 @@ from social.apps.django_app.default.models import UserSocialAuth
from weblate.lang.models import Language from weblate.lang.models import Language
from weblate.trans.util import get_site_url from weblate.trans.util import get_site_url
from weblate.accounts.avatar import get_user_display from weblate.accounts.avatar import get_user_display
from weblate.trans.util import report_error
import weblate import weblate
from weblate.appsettings import ANONYMOUS_USER_NAME, SITE_TITLE from weblate.appsettings import ANONYMOUS_USER_NAME, SITE_TITLE
...@@ -50,6 +52,7 @@ def send_mails(mails): ...@@ -50,6 +52,7 @@ def send_mails(mails):
connection.send_messages(mails) connection.send_messages(mails)
except SMTPException as error: except SMTPException as error:
weblate.logger.error('Failed to send email: %s', error) weblate.logger.error('Failed to send email: %s', error)
report_error(error, sys.exc_info())
def notify_merge_failure(subproject, error, status): def notify_merge_failure(subproject, error, status):
......
...@@ -24,10 +24,12 @@ Base code for machine translation services. ...@@ -24,10 +24,12 @@ Base code for machine translation services.
from django.core.cache import cache from django.core.cache import cache
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
import sys
import json import json
import urllib import urllib
import urllib2 import urllib2
import weblate import weblate
from weblate.trans.util import report_error
class MachineTranslationError(Exception): class MachineTranslationError(Exception):
...@@ -171,11 +173,13 @@ class MachineTranslation(object): ...@@ -171,11 +173,13 @@ class MachineTranslation(object):
try: try:
languages = self.download_languages() languages = self.download_languages()
except Exception as exc: except Exception as exc:
report_error(
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
weblate.logger.error( weblate.logger.error(
'Failed to fetch languages from %s, using defaults (%s: %s)', 'Failed to fetch languages from %s, using defaults',
self.name, self.name,
exc.__class__.__name__,
str(exc)
) )
weblate.logger.error( weblate.logger.error(
'Last fetched URL: %s, params: %s', 'Last fetched URL: %s, params: %s',
...@@ -222,11 +226,13 @@ class MachineTranslation(object): ...@@ -222,11 +226,13 @@ class MachineTranslation(object):
for trans in translations for trans in translations
] ]
except Exception as exc: except Exception as exc:
report_error(
exc, sys.exc_info(),
{'mt_url': self.request_url, 'mt_params': self.request_params}
)
weblate.logger.error( weblate.logger.error(
'Failed to fetch translations from %s (%s: %s)', 'Failed to fetch translations from %s',
self.name, self.name,
exc.__class__.__name__,
str(exc)
) )
weblate.logger.error( weblate.logger.error(
'Last fetched URL: %s, params: %s', 'Last fetched URL: %s, params: %s',
......
...@@ -28,7 +28,7 @@ from django.core.urlresolvers import reverse ...@@ -28,7 +28,7 @@ from django.core.urlresolvers import reverse
from weblate.trans.models import Translation, Dictionary, Change from weblate.trans.models import Translation, Dictionary, Change
from weblate.lang.models import Language from weblate.lang.models import Language
from weblate.trans.util import get_site_url from weblate.trans.util import get_site_url, report_error
from weblate.trans.forms import WordForm, DictUploadForm, LetterForm from weblate.trans.forms import WordForm, DictUploadForm, LetterForm
from weblate.trans.views.helper import get_project from weblate.trans.views.helper import get_project
import weblate import weblate
...@@ -165,6 +165,7 @@ def upload_dictionary(request, project, lang): ...@@ -165,6 +165,7 @@ def upload_dictionary(request, project, lang):
) % count ) % count
) )
except Exception as error: except Exception as error:
report_error(error, sys.exc_info(), request)
messages.error( messages.error(
request, _('File upload has failed: %s') % unicode(error) request, _('File upload has failed: %s') % unicode(error)
) )
......
...@@ -25,7 +25,9 @@ from django.contrib import messages ...@@ -25,7 +25,9 @@ from django.contrib import messages
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from django.http import Http404 from django.http import Http404
import sys
from weblate.trans.util import report_error
from weblate.trans.forms import get_upload_form from weblate.trans.forms import get_upload_form
from weblate.trans.views.helper import get_translation from weblate.trans.views.helper import get_translation
...@@ -135,5 +137,6 @@ def upload_translation(request, project, subproject, lang): ...@@ -135,5 +137,6 @@ def upload_translation(request, project, subproject, lang):
messages.error( messages.error(
request, _('File content merge failed: %s') % unicode(error) request, _('File content merge failed: %s') % unicode(error)
) )
report_error(error, sys.exc_info(), request)
return redirect(obj) return redirect(obj)
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