From 7308c903e2e0e929fbc51119dd82d9c37bfe59fb Mon Sep 17 00:00:00 2001 From: Christian Geier Date: Tue, 3 Sep 2013 16:31:14 +0200 Subject: [PATCH] catch 'broken' vcards broken in a sense that vobject cannot parse them these cards won't get inserted into the db, but instead a warning is printed and, in debug mode, the whole vcard is printed. this should 'take care' of cases like gh #78 for now --- pycarddav/backend.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pycarddav/backend.py b/pycarddav/backend.py index aaca335..581d975 100644 --- a/pycarddav/backend.py +++ b/pycarddav/backend.py @@ -226,7 +226,15 @@ def update(self, vcard, account_name, href='', etag='', status=OK): vcard_s = vcard.decode('utf-8') except UnicodeEncodeError: vcard_s = vcard # incase it's already unicode and py2 - vcard = model.vcard_from_string(vcard) + try: + vcard = model.vcard_from_string(vcard) + except: + logging.error('VCard {0} could not be inserted into the ' + 'db'.format(href)) + if self.debug: + logging.error('could not be converted to vcard') + logging.error(vcard) + return else: vcard_s = vcard.vcf if href == '':