#### 3.2.2 Error Sources

The library `libgpg-error` defines an error source for every component of the GnuPG system. The error source part of an error value is not well defined. As such it is mainly useful to improve the diagnostic error message for the user.

If the error code part of an error value is `0`, the whole error value will be `0`. In this case the error source part is of course `GPG_ERR_SOURCE_UNKNOWN`.

The list of error sources that might occur in applications using Libgcrypt is:

`GPG_ERR_SOURCE_UNKNOWN`

  The error source is not known. The value of this error source is `0`.

`GPG_ERR_SOURCE_GPGME`

  The error source is GPGME itself.

`GPG_ERR_SOURCE_GPG`

  The error source is GnuPG, which is the crypto engine used for the OpenPGP protocol.

`GPG_ERR_SOURCE_GPGSM`

  The error source is GPGSM, which is the crypto engine used for the OpenPGP protocol.

`GPG_ERR_SOURCE_GCRYPT`

  The error source is `libgcrypt`, which is used by crypto engines to perform cryptographic operations.

`GPG_ERR_SOURCE_GPGAGENT`

  The error source is `gpg-agent`, which is used by crypto engines to perform operations with the secret key.

`GPG_ERR_SOURCE_PINENTRY`

  The error source is `pinentry`, which is used by `gpg-agent` to query the passphrase to unlock a secret key.

`GPG_ERR_SOURCE_SCD`

  The error source is the SmartCard Daemon, which is used by `gpg-agent` to delegate operations with the secret key to a SmartCard.

`GPG_ERR_SOURCE_KEYBOX`

  The error source is `libkbx`, a library used by the crypto engines to manage local keyrings.

`GPG_ERR_SOURCE_USER_1`
`GPG_ERR_SOURCE_USER_2`
`GPG_ERR_SOURCE_USER_3`
`GPG_ERR_SOURCE_USER_4`

  These error sources are not used by any GnuPG component and can be used by other software. For example, applications using Libgcrypt can use them to mark error values coming from callback handlers. Thus `GPG_ERR_SOURCE_USER_1` is the default for errors created with `gcry_error` and `gcry_error_from_errno`, unless you define `GCRY_ERR_SOURCE_DEFAULT` before including `gcrypt.h`.