瀏覽代碼

Add some logging / error handling

jherve 1 月之前
父節點
當前提交
d78fb1de75
共有 2 個文件被更改,包括 4 次插入1 次删除
  1. 2 1
      pc_backup/keepass.py
  2. 2 0
      pc_backup/secret.py

+ 2 - 1
pc_backup/keepass.py

@@ -1,4 +1,3 @@
-import os
 import subprocess
 from pathlib import Path
 from dataclasses import dataclass
@@ -13,9 +12,11 @@ class KeePass:
     bin: str | Path
 
     def read_entry_attribute(self, key, attribute):
+        print(f"reading attr {attribute} of key {key}..")
         return self._exec(["show", "-a", attribute, self.path, key]).strip()
 
     def read_entry_attachment(self, key, attachment):
+        print(f"reading attachment {attachment} of key {key}..")
         return self._exec(
             ["attachment-export", "--stdout", self.path, key, attachment, "/dev/null"]
         )

+ 2 - 0
pc_backup/secret.py

@@ -22,6 +22,8 @@ class Secret:
                 sub_class = SecretKeepassAttribute
             case "keepass-attachment":
                 sub_class = SecretKeepassAttachment
+            case _:
+                raise ValueError(f"Cannot read `{line}` as a secret spec")
 
         return sub_class.from_line(name, *args)