浏览代码

save the data for debugging when pgp fails

Son NK 4 年之前
父节点
当前提交
477481c41e
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      app/pgp_utils.py

+ 7 - 1
app/pgp_utils.py

@@ -60,6 +60,12 @@ def encrypt_file(data: BytesIO, fingerprint: str) -> str:
             r = gpg.encrypt_file(data, fingerprint, always_trust=True)
 
         if not r.ok:
-            raise PGPException(f"Cannot encrypt, status: {r.status}")
+            # save the data for debugging
+            data.seek(0)
+            file_path = f"/tmp/{random_string(10)}.eml"
+            with open(file_path, "wb") as f:
+                f.write(data.getbuffer())
+
+            raise PGPException(f"Cannot encrypt, status: {r.status}, {file_path}")
 
     return str(r)