From c739bbfcac6022e01215aee021950e868ea5b4b9 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 13 Dec 2015 01:52:31 +0100 Subject: [PATCH] vobject: Add basic error display for broken items See #300 --- vdirsyncer/utils/vobject.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/vdirsyncer/utils/vobject.py b/vdirsyncer/utils/vobject.py index 374d000..b0650b7 100644 --- a/vdirsyncer/utils/vobject.py +++ b/vdirsyncer/utils/vobject.py @@ -236,19 +236,23 @@ class _Component(object): stack = [] rv = [] - for line in lines: - if line.startswith(u'BEGIN:'): - c_name = line[len(u'BEGIN:'):].strip().upper() - stack.append(cls(c_name, [], [])) - elif line.startswith(u'END:'): - component = stack.pop() - if stack: - stack[-1].subcomponents.append(component) + try: + for i, line in enumerate(lines): + if line.startswith(u'BEGIN:'): + c_name = line[len(u'BEGIN:'):].strip().upper() + stack.append(cls(c_name, [], [])) + elif line.startswith(u'END:'): + component = stack.pop() + if stack: + stack[-1].subcomponents.append(component) + else: + rv.append(component) else: - rv.append(component) - else: - if line.strip(): - stack[-1].props.append(line) + if line.strip(): + stack[-1].props.append(line) + except IndexError: + raise ValueError('Parsing error at line {}. Check the debug log ' + 'for more information.'.format(i + 1)) if multiple: return rv