aboutsummaryrefslogtreecommitdiffstats
path: root/g10/misc.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-12-14 18:35:03 +0000
committerWerner Koch <[email protected]>2015-12-15 12:40:10 +0000
commit2ea1aebc924c3f0b2269f83cb1b80c75d9fa069c (patch)
treee4deb768059ed642a19b580ab24ad535778373b5 /g10/misc.c
parentgpg: Improve the keyblock cache's transparency. (diff)
downloadgnupg-2ea1aebc924c3f0b2269f83cb1b80c75d9fa069c.tar.gz
gnupg-2ea1aebc924c3f0b2269f83cb1b80c75d9fa069c.zip
gpg: New function to printed a detailed error code.
* g10/misc.c (print_reported_error): New. -- Often the user is only interested in a catch all error code like "not found" but sometimes it is useful to also see the real reason. By this function this can easily be achieved. Example: err = search_for_key (keyid) if (err) { log_info ("error locating key '%s': %s\n", keyid, gpg_strerror (GPG_ERR_NOT_FOUND)); print_reported_error (err, GPG_ERR_NOT_FOUND); } results in gpg: error locating key 'foobar': not found gpg: (reported error: no keyring <keybox>) where the second line is only printed in verbose mode and if ERR is not GPG_ERR_NOT_FOUND. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/misc.c')
-rw-r--r--g10/misc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/g10/misc.c b/g10/misc.c
index 547944d34..57d5fef80 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -358,6 +358,31 @@ print_digest_rejected_note (enum gcry_md_algos algo)
}
+/* Print a message
+ * "(reported error: %s)\n
+ * in verbose mode to further explain an error. If the error code has
+ * the value IGNORE_EC no message is printed. A message is also not
+ * printed if ERR is 0. */
+void
+print_reported_error (gpg_error_t err, gpg_err_code_t ignore_ec)
+{
+ if (!opt.verbose)
+ return;
+
+ if (!gpg_err_code (err))
+ ;
+ else if (gpg_err_code (err) == ignore_ec)
+ ;
+ else if (gpg_err_source (err) == GPG_ERR_SOURCE_DEFAULT)
+ log_info (_("(reported error: %s\n)"),
+ gpg_strerror (err));
+ else
+ log_info (_("(reported error: %s <%s>\n)"),
+ gpg_strerror (err), gpg_strsource (err));
+
+}
+
+
/* Map OpenPGP algo numbers to those used by Libgcrypt. We need to do
this for algorithms we implemented in Libgcrypt after they become
part of OpenPGP. */