forked from awslabs/aws-c-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.h
108 lines (90 loc) · 3.87 KB
/
error.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef AWS_COMMON_ERROR_H_
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#define AWS_COMMON_ERROR_H_
#include <aws/common/exports.h>
#include <stdint.h>
struct aws_error_info {
int error_code;
const char *literal_name;
const char *error_str;
const char *lib_name;
const char *formatted_name;
};
struct aws_error_info_list {
const struct aws_error_info *error_list;
uint16_t count;
};
#define AWS_DEFINE_ERROR_INFO(NAME, C, ES, LN) \
{ \
.literal_name = #C, \
.error_code = C, \
.error_str = ES, \
.lib_name = LN, \
.formatted_name = LN ": " #C ", " ES \
}
typedef void(*aws_error_handler)(int err, void *ctx);
#ifdef __cplusplus
extern "C" {
#endif
/*
* Returns the latest error code on the current thread, or 0 if none have occurred.
*/
AWS_COMMON_API int aws_last_error(void);
/*
* Returns the error str corresponding to `err`.
*/
AWS_COMMON_API const char *aws_error_str(int err);
/*
* Returns the error lib name corresponding to `err`.
*/
AWS_COMMON_API const char *aws_error_lib_name(int err);
/*
* Returns libname concatenated with error string.
*/
AWS_COMMON_API const char *aws_error_debug_str(int err);
/*
* Raises `err` to the installed callbacks, and sets the thread's error.
*/
AWS_COMMON_API int aws_raise_error(int err);
/*
* Resets the `err` back to defaults
*/
AWS_COMMON_API void aws_reset_error(void);
/*
* Sets `err` to the latest error. Does not invoke callbacks.
*/
AWS_COMMON_API void aws_restore_error(int err);
/*
* Sets an application wide error handler function. This will be overridden by the thread local handler.
* The previous handler is returned, this can be used for restoring an error handler if it needs to be overridden
* temporarily. Setting this to NULL will turn off this error callback after it has been enabled.
*/
AWS_COMMON_API aws_error_handler aws_set_global_error_handler_fn(aws_error_handler handler, void *ctx);
/*
* Sets a thread-local error handler function. This will override the global handler. The previous handler is returned,
* this can be used for restoring an error handler if it needs to be overridden temporarily. Setting this to NULL will
* turn off this error callback after it has been enabled.
*/
AWS_COMMON_API aws_error_handler aws_set_thread_local_error_handler_fn(aws_error_handler handler, void *ctx);
/** TODO: this needs to be a private function (wait till we have the cmake story better before moving it though).
* It should be external for the purpose of other libs we own,
* but customers should not be able to hit it without going out of their way to do so.
*/
AWS_COMMON_API void aws_register_error_info(const struct aws_error_info_list *error_info);
#ifdef __cplusplus
}
#endif
#endif /* AWS_COMMON_ERROR_H_ */