## Error reporting Error reporting — Representation of recoverable errors. |

## Synopsis

    enum                PolKitErrorCode;
                        PolKitError;
    polkit_bool_t       polkit_error_is_set                 (PolKitError *error);
    const char *        polkit_error_get_error_name         (PolKitError *error);
    PolKitErrorCode     polkit_error_get_error_code         (PolKitError *error);
    const char *        polkit_error_get_error_message      (PolKitError *error);
    void                polkit_error_free                   (PolKitError *error);
    polkit_bool_t       polkit_error_set_error              (PolKitError **error,
                                                             PolKitErrorCode error_code,
                                                             const char *format,
                                                             ...);

## Description

Error codes from PolicyKit.

## Details

### enum PolKitErrorCode

    typedef enum
    {
            POLKIT_ERROR_OUT_OF_MEMORY,
            POLKIT_ERROR_POLICY_FILE_INVALID,
            POLKIT_ERROR_GENERAL_ERROR,
            POLKIT_ERROR_NOT_AUTHORIZED_TO_READ_AUTHORIZATIONS_FOR_OTHER_USERS,
            POLKIT_ERROR_NOT_AUTHORIZED_TO_REVOKE_AUTHORIZATIONS_FROM_OTHER_USERS,
            POLKIT_ERROR_NOT_AUTHORIZED_TO_GRANT_AUTHORIZATION,
            POLKIT_ERROR_AUTHORIZATION_ALREADY_EXISTS,
            POLKIT_ERROR_NOT_SUPPORTED,
            POLKIT_ERROR_NOT_AUTHORIZED_TO_MODIFY_DEFAULTS,

            POLKIT_ERROR_NUM_ERROR_CODES
    } PolKitErrorCode;

Errors returned by PolicyKit

`POLKIT_ERROR_OUT_OF_MEMORY` | Out of memory
`POLKIT_ERROR_POLICY_FILE_INVALID` | There was an error parsing the given policy file
`POLKIT_ERROR_GENERAL_ERROR` | A general error code typically indicating problems with the installation of PolicyKit, e.g. helpers missing or wrong owner / permission.
`POLKIT_ERROR_NOT_AUTHORIZED_TO_READ_AUTHORIZATIONS_FOR_OTHER_USERS` | An attempt was made to read authorizations for other users and the calling process is not authorized.
`POLKIT_ERROR_NOT_AUTHORIZED_TO_REVOKE_AUTHORIZATIONS_FROM_OTHER_USERS` | An attempt was made to revoke authorizations for other users and the calling process is not authorized.
`POLKIT_ERROR_NOT_AUTHORIZED_TO_GRANT_AUTHORIZATION` | An attempt was made to grant an authorization and the calling process is not authorized.
`POLKIT_ERROR_AUTHORIZATION_ALREADY_EXISTS` | Subject already has an similar authorization already (modulo time of grant and who granted).
`POLKIT_ERROR_NOT_SUPPORTED` | The operation is not supported by the authorization database backend
`POLKIT_ERROR_NOT_AUTHORIZED_TO_MODIFY_DEFAULTS` | An attempt was made to modify the defaults for implicit authorizations and the calling process is not authorized.
`POLKIT_ERROR_NUM_ERROR_CODES` | Number of error codes. This may change from version to version; do not rely on it.

### PolKitError

    typedef struct _PolKitError PolKitError;

Objects of this class are used for error reporting.

### polkit_error_is_set ()

    polkit_bool_t       polkit_error_is_set                 (PolKitError *error);

Determine if an error set

`error` : | the error
Returns : | TRUE if, and only if, the error is set

Since 0.7

### polkit_error_get_error_name ()

    const char *        polkit_error_get_error_name         (PolKitError *error);

Get the CamelCase name for the error; e.g. POLKIT_ERROR_OUT_OF_MEMORY maps to "OutOfMemory" and so on.

`error` : | the error
Returns : | the string

Since 0.7

### polkit_error_get_error_code ()

    PolKitErrorCode     polkit_error_get_error_code         (PolKitError *error);

Returns the error code.

`error` : | the error object
Returns : | A value from the PolKitErrorCode enumeration.

### polkit_error_get_error_message ()

    const char *        polkit_error_get_error_message      (PolKitError *error);

Get the error message.

`error` : | the error object
Returns : | A string describing the error. Caller shall not free this string.

### polkit_error_free ()

    void                polkit_error_free                   (PolKitError *error);

Free an error.

`error` : | the error

### polkit_error_set_error ()

    polkit_bool_t       polkit_error_set_error              (PolKitError **error,
                                                             PolKitErrorCode error_code,
                                                             const char *format,
                                                             ...);

Sets an error. If OOM, the error will be set to a pre-allocated OOM error.

`error` : | the error object
`error_code` : | A value from the PolKitErrorCode enumeration.
`format` : | printf style formatting string
`...` : | printf style arguments
Returns : | TRUE if the error was set