Catch exceptions for every entry property

Fixes #6
This commit is contained in:
David Němec 2021-04-21 11:28:29 +02:00
parent 12be55fec2
commit 3bb5f3be3b
No known key found for this signature in database
GPG Key ID: B1064EFFFD11AA75
2 changed files with 43 additions and 41 deletions

View File

@ -46,8 +46,8 @@ def bitwarden_to_keepass(args):
bw_item = Item(item)
is_duplicate_title = False
try:
while True:
entry = None
entry_title = bw_item.get_name() if not is_duplicate_title else '{name} - ({item_id}'.format(name=bw_item.get_name(), item_id=bw_item.get_id())
try:
entry = kp.add_entry(
@ -62,12 +62,7 @@ def bitwarden_to_keepass(args):
if 'already exists' in str(e):
is_duplicate_title = True
continue
logging.warning(f'Skipping item named "{item["name"]}" because of this error: {repr(e)}')
break
if not entry:
continue
raise
totp_secret, totp_settings = bw_item.get_totp()
if totp_secret and totp_settings:
@ -91,6 +86,10 @@ def bitwarden_to_keepass(args):
entry.add_attachment(attachment_id, attachment['fileName'])
os.remove(attachment_path)
except Exception as e:
logging.warning(f'Skipping item named "{item["name"]}" because of this error: {repr(e)}')
continue
logging.info('Saving changes to KeePass database.')
kp.save()
logging.info('Export completed.')

View File

@ -41,6 +41,9 @@ class Item:
if 'login' not in self.item or 'uris' not in self.item['login']:
return []
for uri in self.item['login']['uris']:
uri['uri'] = uri['uri'] if uri['uri'] is not None else ''
return self.item['login']['uris']
def get_custom_fields(self):