Skip to content

create PyKeePassException #385

Description

@Evidlo

There are lots of cases right now where PyKeePass allows internal exceptions to bubble up to the end-user. We should consider catching some of these where it makes sense and raising a PyKeePassException that is more descriptive.

e.g. A user tries to dereference a field when the reference doesn't exist

>>> kp.entries[0].username = '{REF:U@I:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}'

>>> kp.deref(kp.entries[0].username)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[23], line 1
----> 1 kp.deref(kp.entries[0].username)

File ~/resources/pykeepass/pykeepass/pykeepass.py:703, in PyKeePass.deref(self, value)
    701         search_value = uuid.UUID(search_value)
    702     ref_entry = self.find_entries(first=True, **{search_in: search_value})
--> 703     value = value.replace(ref, getattr(ref_entry, wanted_field))
    704 return self.deref(value)

AttributeError: 'NoneType' object has no attribute 'username'

I'd like to collate a list of these cases here. Maybe @A6GibKm @FalkAlexander @firecat53 have some examples?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions