1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-28 22:49:59 +01:00

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 <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-12-14 19:35:03 +01:00
parent f369efd671
commit 2ea1aebc92
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 26 additions and 0 deletions

View File

@ -89,6 +89,7 @@ void print_pubkey_algo_note (pubkey_algo_t algo);
void print_cipher_algo_note (cipher_algo_t algo); void print_cipher_algo_note (cipher_algo_t algo);
void print_digest_algo_note (digest_algo_t algo); void print_digest_algo_note (digest_algo_t algo);
void print_digest_rejected_note (enum gcry_md_algos algo); void print_digest_rejected_note (enum gcry_md_algos algo);
void print_reported_error (gpg_error_t err, gpg_err_code_t skip_if_ec);
void additional_weak_digest (const char* digestname); void additional_weak_digest (const char* digestname);
/*-- armor.c --*/ /*-- armor.c --*/

View File

@ -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 /* Map OpenPGP algo numbers to those used by Libgcrypt. We need to do
this for algorithms we implemented in Libgcrypt after they become this for algorithms we implemented in Libgcrypt after they become
part of OpenPGP. */ part of OpenPGP. */