save the data for debugging when pgp fails

This commit is contained in:
Son NK 2020-10-24 19:03:19 +02:00
parent 83f3309149
commit 477481c41e
1 changed files with 7 additions and 1 deletions

View File

@ -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)