backups: Improve handling borg errors

- Use regular expression search instead of string search.

- Fix issue with incorrect password error not getting recognized properly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-08-28 22:05:22 -07:00 committed by James Valleroy
parent 77a93d967f
commit c159c484ec
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -23,6 +23,7 @@ import io
import json
import logging
import os
import re
from uuid import uuid1
from django.utils.translation import ugettext_lazy as _
@ -64,12 +65,9 @@ KNOWN_ERRORS = [{
BorgRepositoryDoesNotExistError,
},
{
'errors': [('passphrase supplied in BORG_PASSPHRASE or by '
'BORG_PASSCOMMAND is incorrect')],
'message':
_('Incorrect encryption passphrase'),
'raise_as':
BorgError,
'errors': [('passphrase supplied in .* is incorrect')],
'message': _('Incorrect encryption passphrase'),
'raise_as': BorgError,
},
{
'errors': [('Connection reset by peer')],
@ -255,7 +253,7 @@ class BaseBorgRepository(abc.ABC):
caught_error = str(err)
for known_error in KNOWN_ERRORS:
for error in known_error['errors']:
if error in caught_error:
if re.search(error, caught_error):
raise known_error['raise_as'](known_error['message'])
raise err