LCOV - code coverage report
Current view: top level - aws-c-common/include/aws/common - error.h (source / functions) Hit Total Coverage
Test: all_fuzz.info Lines: 2 4 50.0 %
Date: 2021-04-23 16:28:21 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef AWS_COMMON_ERROR_H
       2             : #define AWS_COMMON_ERROR_H
       3             : 
       4             : /**
       5             :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       6             :  * SPDX-License-Identifier: Apache-2.0.
       7             :  */
       8             : 
       9             : #include <aws/common/assert.h>
      10             : #include <aws/common/exports.h>
      11             : #include <aws/common/macros.h>
      12             : #include <aws/common/package.h>
      13             : #include <aws/common/stdint.h>
      14             : 
      15    30245862 : #define AWS_OP_SUCCESS (0)
      16      542633 : #define AWS_OP_ERR (-1)
      17             : 
      18             : /* Each library gets space for 2^^10 error entries */
      19           0 : #define AWS_ERROR_ENUM_STRIDE_BITS 10
      20           0 : #define AWS_ERROR_ENUM_STRIDE (1U << AWS_ERROR_ENUM_STRIDE_BITS)
      21             : #define AWS_ERROR_ENUM_BEGIN_RANGE(x) ((x)*AWS_ERROR_ENUM_STRIDE)
      22             : #define AWS_ERROR_ENUM_END_RANGE(x) (((x) + 1) * AWS_ERROR_ENUM_STRIDE - 1)
      23             : 
      24             : struct aws_error_info {
      25             :     int error_code;
      26             :     const char *literal_name;
      27             :     const char *error_str;
      28             :     const char *lib_name;
      29             :     const char *formatted_name;
      30             : };
      31             : 
      32             : struct aws_error_info_list {
      33             :     const struct aws_error_info *error_list;
      34             :     uint16_t count;
      35             : };
      36             : 
      37             : #define AWS_DEFINE_ERROR_INFO(C, ES, LN)                                                                               \
      38             :     {                                                                                                                  \
      39             :         .literal_name = #C, .error_code = (C), .error_str = (ES), .lib_name = (LN),                                    \
      40             :         .formatted_name = LN ": " #C ", " ES,                                                                          \
      41             :     }
      42             : 
      43             : typedef void(aws_error_handler_fn)(int err, void *ctx);
      44             : 
      45             : AWS_EXTERN_C_BEGIN
      46             : 
      47             : /*
      48             :  * Returns the latest error code on the current thread, or 0 if none have
      49             :  * occurred.
      50             :  */
      51             : AWS_COMMON_API
      52             : int aws_last_error(void);
      53             : 
      54             : /*
      55             :  * Returns the error str corresponding to `err`.
      56             :  */
      57             : AWS_COMMON_API
      58             : const char *aws_error_str(int err);
      59             : 
      60             : /*
      61             :  * Returns the enum name corresponding to `err`.
      62             :  */
      63             : AWS_COMMON_API
      64             : const char *aws_error_name(int err);
      65             : 
      66             : /*
      67             :  * Returns the error lib name corresponding to `err`.
      68             :  */
      69             : AWS_COMMON_API
      70             : const char *aws_error_lib_name(int err);
      71             : 
      72             : /*
      73             :  * Returns libname concatenated with error string.
      74             :  */
      75             : AWS_COMMON_API
      76             : const char *aws_error_debug_str(int err);
      77             : 
      78             : /*
      79             :  * Internal implementation detail.
      80             :  */
      81             : AWS_COMMON_API
      82             : void aws_raise_error_private(int err);
      83             : 
      84             : /*
      85             :  * Raises `err` to the installed callbacks, and sets the thread's error.
      86             :  */
      87             : AWS_STATIC_IMPL
      88             : int aws_raise_error(int err);
      89             : 
      90             : /*
      91             :  * Resets the `err` back to defaults
      92             :  */
      93             : AWS_COMMON_API
      94             : void aws_reset_error(void);
      95             : /*
      96             :  * Sets `err` to the latest error. Does not invoke callbacks.
      97             :  */
      98             : AWS_COMMON_API
      99             : void aws_restore_error(int err);
     100             : 
     101             : /*
     102             :  * Sets an application wide error handler function. This will be overridden by
     103             :  * the thread local handler. The previous handler is returned, this can be used
     104             :  * for restoring an error handler if it needs to be overridden temporarily.
     105             :  * Setting this to NULL will turn off this error callback after it has been
     106             :  * enabled.
     107             :  */
     108             : AWS_COMMON_API
     109             : aws_error_handler_fn *aws_set_global_error_handler_fn(aws_error_handler_fn *handler, void *ctx);
     110             : 
     111             : /*
     112             :  * Sets a thread-local error handler function. This will override the global
     113             :  * handler. The previous handler is returned, this can be used for restoring an
     114             :  * error handler if it needs to be overridden temporarily. Setting this to NULL
     115             :  * will turn off this error callback after it has been enabled.
     116             :  */
     117             : AWS_COMMON_API
     118             : aws_error_handler_fn *aws_set_thread_local_error_handler_fn(aws_error_handler_fn *handler, void *ctx);
     119             : 
     120             : /** TODO: this needs to be a private function (wait till we have the cmake story
     121             :  * better before moving it though). It should be external for the purpose of
     122             :  * other libs we own, but customers should not be able to hit it without going
     123             :  * out of their way to do so.
     124             :  */
     125             : AWS_COMMON_API
     126             : void aws_register_error_info(const struct aws_error_info_list *error_info);
     127             : 
     128             : AWS_COMMON_API
     129             : void aws_unregister_error_info(const struct aws_error_info_list *error_info);
     130             : 
     131             : /**
     132             :  * Convert a c library io error into an aws error.
     133             :  */
     134             : AWS_COMMON_API
     135             : int aws_translate_and_raise_io_error(int error_no);
     136             : 
     137             : #ifndef AWS_NO_STATIC_IMPL
     138             : #    include <aws/common/error.inl>
     139             : #endif /* AWS_NO_STATIC_IMPL */
     140             : 
     141             : AWS_EXTERN_C_END
     142             : 
     143             : enum aws_common_error {
     144             :     AWS_ERROR_SUCCESS = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_COMMON_PACKAGE_ID),
     145             :     AWS_ERROR_OOM,
     146             :     AWS_ERROR_NO_SPACE,
     147             :     AWS_ERROR_UNKNOWN,
     148             :     AWS_ERROR_SHORT_BUFFER,
     149             :     AWS_ERROR_OVERFLOW_DETECTED,
     150             :     AWS_ERROR_UNSUPPORTED_OPERATION,
     151             :     AWS_ERROR_INVALID_BUFFER_SIZE,
     152             :     AWS_ERROR_INVALID_HEX_STR,
     153             :     AWS_ERROR_INVALID_BASE64_STR,
     154             :     AWS_ERROR_INVALID_INDEX,
     155             :     AWS_ERROR_THREAD_INVALID_SETTINGS,
     156             :     AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE,
     157             :     AWS_ERROR_THREAD_NO_PERMISSIONS,
     158             :     AWS_ERROR_THREAD_NOT_JOINABLE,
     159             :     AWS_ERROR_THREAD_NO_SUCH_THREAD_ID,
     160             :     AWS_ERROR_THREAD_DEADLOCK_DETECTED,
     161             :     AWS_ERROR_MUTEX_NOT_INIT,
     162             :     AWS_ERROR_MUTEX_TIMEOUT,
     163             :     AWS_ERROR_MUTEX_CALLER_NOT_OWNER,
     164             :     AWS_ERROR_MUTEX_FAILED,
     165             :     AWS_ERROR_COND_VARIABLE_INIT_FAILED,
     166             :     AWS_ERROR_COND_VARIABLE_TIMED_OUT,
     167             :     AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN,
     168             :     AWS_ERROR_CLOCK_FAILURE,
     169             :     AWS_ERROR_LIST_EMPTY,
     170             :     AWS_ERROR_DEST_COPY_TOO_SMALL,
     171             :     AWS_ERROR_LIST_EXCEEDS_MAX_SIZE,
     172             :     AWS_ERROR_LIST_STATIC_MODE_CANT_SHRINK,
     173             :     AWS_ERROR_PRIORITY_QUEUE_FULL,
     174             :     AWS_ERROR_PRIORITY_QUEUE_EMPTY,
     175             :     AWS_ERROR_PRIORITY_QUEUE_BAD_NODE,
     176             :     AWS_ERROR_HASHTBL_ITEM_NOT_FOUND,
     177             :     AWS_ERROR_INVALID_DATE_STR,
     178             :     AWS_ERROR_INVALID_ARGUMENT,
     179             :     AWS_ERROR_RANDOM_GEN_FAILED,
     180             :     AWS_ERROR_MALFORMED_INPUT_STRING,
     181             :     AWS_ERROR_UNIMPLEMENTED,
     182             :     AWS_ERROR_INVALID_STATE,
     183             :     AWS_ERROR_ENVIRONMENT_GET,
     184             :     AWS_ERROR_ENVIRONMENT_SET,
     185             :     AWS_ERROR_ENVIRONMENT_UNSET,
     186             :     AWS_ERROR_STREAM_UNSEEKABLE,
     187             :     AWS_ERROR_NO_PERMISSION,
     188             :     AWS_ERROR_FILE_INVALID_PATH,
     189             :     AWS_ERROR_MAX_FDS_EXCEEDED,
     190             :     AWS_ERROR_SYS_CALL_FAILURE,
     191             :     AWS_ERROR_C_STRING_BUFFER_NOT_NULL_TERMINATED,
     192             :     AWS_ERROR_STRING_MATCH_NOT_FOUND,
     193             :     AWS_ERROR_DIVIDE_BY_ZERO,
     194             : 
     195             :     AWS_ERROR_END_COMMON_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_COMMON_PACKAGE_ID)
     196             : };
     197             : 
     198             : #endif /* AWS_COMMON_ERROR_H */

Generated by: LCOV version 1.13