Selaa lähdekoodia

save the data for debugging when pgp fails

Son NK 4 vuotta sitten
vanhempi
commit
477481c41e
1 muutettua tiedostoa jossa 7 lisäystä ja 1 poistoa
  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)