10 * Type used for error codes is an explicitly *unsigned* int, meaning that error codes themselves are positive. |
10 * Type used for error codes is an explicitly *unsigned* int, meaning that error codes themselves are positive. |
11 * Negative error codes also exist in some places, and they are just a negative err_t. |
11 * Negative error codes also exist in some places, and they are just a negative err_t. |
12 */ |
12 */ |
13 typedef unsigned int err_t; |
13 typedef unsigned int err_t; |
14 |
14 |
15 /* |
15 /** |
16 * Bitmask of error_info.extra meanings |
16 * Ways to interpret error_info.extra |
17 */ |
17 */ |
18 enum error_extra_types { |
18 enum error_extra_types { |
19 // bit offset of ERR_EXTRA_* mask in error_code |
19 ERR_EXTRA_NONE = 0, |
20 _ERR_EXTRA_OFFSET = 3 * 8, |
|
21 |
|
22 // mask of bits used for the error_extra_types value |
|
23 _ERR_EXTRA_MASK = 0xff << _ERR_EXTRA_OFFSET, |
|
24 |
20 |
25 ERR_EXTRA_NONE = 0x00 << _ERR_EXTRA_OFFSET, |
21 /** libc errno, using strerror() */ |
26 ERR_EXTRA_ERRNO = 0x01 << _ERR_EXTRA_OFFSET, |
22 ERR_EXTRA_ERRNO, |
27 ERR_EXTRA_GAI = 0x02 << _ERR_EXTRA_OFFSET, |
23 |
28 ERR_EXTRA_GNUTLS = 0x03 << _ERR_EXTRA_OFFSET, |
24 /** libc resolver, using gai_strerror() */ |
29 |
25 ERR_EXTRA_GAI, |
|
26 |
|
27 /** gnutls, using gnutls_strerror() */ |
|
28 ERR_EXTRA_GNUTLS, |
30 }; |
29 }; |
31 |
30 |
32 |
31 /** |
33 #define _ERROR_CODE(name, code, extra) name = (code | ERR_EXTRA_ ## extra) |
|
34 /* |
|
35 * List of defined error codes, organized mostly by function name |
32 * List of defined error codes, organized mostly by function name |
36 */ |
33 */ |
37 enum error_code { |
34 enum error_code { |
38 /* Core functions */ |
35 _ERR_INVALID = 0x000000, |
39 _ERROR_CODE( ERR_CALLOC, 0x000100, NONE ), |
|
40 |
36 |
41 /* Network resolver errors */ |
37 /** stdlib.h functions */ |
42 _ERROR_CODE( ERR_GETADDRINFO, 0x000200, GAI ), |
38 _ERR_STDLIB = 0x000100, |
43 _ERROR_CODE( ERR_GETADDRINFO_EMPTY, 0x000201, NONE ), |
39 ERR_CALLOC, |
|
40 |
|
41 /** DNS resolver */ |
|
42 _ERR_RESOLVER = 0x000200, |
|
43 ERR_GETADDRINFO, |
|
44 ERR_GETADDRINFO_EMPTY, |
|
45 |
|
46 /** @see enum sock_error_code*/ |
|
47 _ERR_SOCK = 0x000300, |
44 |
48 |
45 /* Low-level network errors */ |
49 /** @see enum sock_gnutls_error_code */ |
46 _ERROR_CODE( ERR_SOCKET, 0x000301, ERRNO ), |
50 _ERR_GNUTLS = 0x000400, |
47 _ERROR_CODE( ERR_CONNECT, 0x000302, ERRNO ), |
|
48 |
51 |
49 /* Low-level IO errors */ |
52 /** Libevent errors */ |
50 _ERROR_CODE( ERR_READ, 0x000401, ERRNO ), |
53 _ERR_LIBEVENT = 0x000500, |
51 _ERROR_CODE( ERR_READ_EOF, 0x000402, NONE ), |
54 ERR_EVENT_NEW, |
52 _ERROR_CODE( ERR_WRITE, 0x000403, ERRNO ), |
55 ERR_EVENT_ADD, |
53 _ERROR_CODE( ERR_WRITE_EOF, 0x000404, NONE ), |
|
54 _ERROR_CODE( ERR_FCNTL, 0x000405, ERRNO ), |
|
55 _ERROR_CODE( ERR_CLOSE, 0x000406, ERRNO ), |
|
56 |
56 |
57 /* GnuTLS errors */ |
57 /** Evsql errors */ |
58 _ERROR_CODE( ERR_GNUTLS_CERT_ALLOC_CRED, 0x010101, GNUTLS ), |
58 _ERR_EVSQL = 0x000600, |
59 _ERROR_CODE( ERR_GNUTLS_GLOBAL_INIT, 0x010102, GNUTLS ), |
59 ERR_EVSQL_NEW_PQ, |
60 _ERROR_CODE( ERR_GNUTLS_INIT, 0x010103, GNUTLS ), |
|
61 _ERROR_CODE( ERR_GNUTLS_SET_DEFAULT_PRIORITY, 0x010104, GNUTLS ), |
|
62 _ERROR_CODE( ERR_GNUTLS_CRED_SET, 0x010105, GNUTLS ), |
|
63 _ERROR_CODE( ERR_GNUTLS_HANDSHAKE, 0x010106, GNUTLS ), |
|
64 _ERROR_CODE( ERR_GNUTLS_RECORD_SEND, 0x010107, GNUTLS ), |
|
65 _ERROR_CODE( ERR_GNUTLS_RECORD_RECV, 0x010108, GNUTLS ), |
|
66 _ERROR_CODE( ERR_GNUTLS_RECORD_GET_DIRECTION, 0x010109, GNUTLS ), |
|
67 |
60 |
68 /* Libevent errors */ |
61 /** irc_line errors */ |
69 _ERROR_CODE( ERR_EVENT_NEW, 0x010201, NONE ), |
62 _ERR_IRC_LINE = 0x000700, |
70 _ERROR_CODE( ERR_EVENT_ADD, 0x010202, NONE ), |
63 ERR_LINE_TOO_LONG, |
71 |
64 ERR_LINE_INVALID_TOKEN, |
72 /* Evsql errors */ |
|
73 _ERROR_CODE( ERR_EVSQL_NEW_PQ, 0x010301, NONE ), |
|
74 |
|
75 /* irc_line errors */ |
|
76 _ERROR_CODE( ERR_LINE_TOO_LONG, 0x100101, NONE ), |
|
77 _ERROR_CODE( ERR_LINE_INVALID_TOKEN, 0x100102, NONE ), |
|
78 |
65 |
79 /** irc_conn errors */ |
66 /** irc_conn errors */ |
80 _ERROR_CODE( ERR_IRC_CONN_REGISTER_STATE, 0x100201, NONE ), |
67 _ERR_IRC_CONN = 0x000800, |
81 |
68 ERR_IRC_CONN_REGISTER_STATE, |
82 // mask of bits used for the error_code value |
69 }; |
83 _ERROR_CODE_MASK = 0xffffff, |
70 |
|
71 /** |
|
72 * Table of error descriptions |
|
73 */ |
|
74 struct error_desc { |
|
75 /** The flat error code */ |
|
76 err_t code; |
|
77 |
|
78 /** The short name */ |
|
79 const char *name; |
|
80 |
|
81 /** How to interpret .extra */ |
|
82 enum error_extra_types extra_type; |
84 }; |
83 }; |
85 |
84 |
86 /* |
85 /* |
87 * An error code and associated extra infos |
86 * An error code and associated extra infos |
88 */ |
87 */ |