commit 300d2bea679f153c64c585129849c0a8af947afe
parent bd8b1a33274539ee5c07512bb530d515ca07d7f8
Author: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:09:23 +0100
Unify formatting of GPGME error messages
Create a private function to turn a an exception into a "human friendly"
error message and to add a entry to the logfile. Use this function for
all error paths.
Signed-off-by: Hamish Downer
Diffstat:
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -106,8 +106,7 @@ EOS
begin
sig = GPGME.detach_sign(format_payload(payload), gpg_opts)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- raise Error, "GPG command failed. See log for details."
+ raise Error, gpgme_exc_msg(exc.message)
end
# if the key (or gpg-agent) is not available GPGME does not complain
@@ -141,8 +140,7 @@ EOS
begin
cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- raise Error, "GPG command failed. See log for details."
+ raise Error, gpgme_exc_msg(exc.message)
end
# if the key (or gpg-agent) is not available GPGME does not complain
@@ -232,7 +230,7 @@ EOS
begin
ctx.verify(sig_data, signed_text_data, plain_data)
rescue GPGME::Error => exc
- return unknown_status exc.message
+ return unknown_status [gpgme_exc_msg(exc.message)]
end
self.verified_ok? ctx.verify_result
end
@@ -250,8 +248,7 @@ EOS
begin
ctx.decrypt_verify(cipher_data, plain_data)
rescue GPGME::Error => exc
- info "Error while running gpg: #{exc.message}"
- return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", exc.message)
+ return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", gpgme_exc_msg(exc.message))
end
sig = self.verified_ok? ctx.verify_result
plain_data.seek(0, IO::SEEK_SET)
@@ -309,6 +306,12 @@ private
Chunk::CryptoNotice.new :unknown, "Unable to determine validity of cryptographic signature", lines
end
+ def gpgme_exc_msg msg
+ err_msg = "Exception in GPGME call: #{msg}"
+ info err_msg
+ err_msg
+ end
+
## here's where we munge rmail output into the format that signed/encrypted
## PGP/GPG messages should be
def format_payload payload