stumpless  2.1.0
error.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 
3 /*
4  * Copyright 2018-2022 Joel E. Anderson
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
23 #ifndef __STUMPLESS_ERROR_H
24 # define __STUMPLESS_ERROR_H
25 
26 #include <stdbool.h>
27 #include <stdio.h>
28 #include <stumpless/config.h>
29 #include <stumpless/generator.h>
30 
31 # ifdef __cplusplus
32 extern "C" {
33 # endif
34 
38 #define STUMPLESS_FOREACH_ERROR(ERROR) \
39 \
44  ERROR(STUMPLESS_ADDRESS_FAILURE, 0) \
45 \
46  ERROR(STUMPLESS_ARGUMENT_EMPTY, 1) \
47 \
48  ERROR(STUMPLESS_ARGUMENT_TOO_BIG, 2) \
49 \
54  ERROR(STUMPLESS_DUPLICATE_ELEMENT, 3) \
55 \
60  ERROR(STUMPLESS_ELEMENT_NOT_FOUND, 4) \
61 \
62  ERROR(STUMPLESS_FILE_OPEN_FAILURE, 5) \
63 \
64  ERROR(STUMPLESS_FILE_WRITE_FAILURE, 6) \
65 \
66  ERROR(STUMPLESS_INDEX_OUT_OF_BOUNDS, 7) \
67 \
68  ERROR(STUMPLESS_INVALID_FACILITY, 8) \
69 \
70  ERROR(STUMPLESS_INVALID_ID, 9) \
71 \
76  ERROR(STUMPLESS_INVALID_SEVERITY, 10) \
77 \
78  ERROR(STUMPLESS_MEMORY_ALLOCATION_FAILURE, 11) \
79 \
80  ERROR(STUMPLESS_NETWORK_PROTOCOL_UNSUPPORTED, 12) \
81 \
86  ERROR(STUMPLESS_PARAM_NOT_FOUND, 13) \
87 \
88  ERROR(STUMPLESS_SOCKET_BIND_FAILURE, 14) \
89 \
90  ERROR(STUMPLESS_SOCKET_CONNECT_FAILURE, 15) \
91 \
92  ERROR(STUMPLESS_SOCKET_FAILURE, 16) \
93 \
94  ERROR(STUMPLESS_SOCKET_SEND_FAILURE, 17) \
95 \
96  ERROR(STUMPLESS_STREAM_WRITE_FAILURE, 18) \
97 \
98  ERROR(STUMPLESS_TARGET_INCOMPATIBLE, 19) \
99 \
100  ERROR(STUMPLESS_TARGET_UNSUPPORTED, 20) \
101 \
102  ERROR(STUMPLESS_TRANSPORT_PROTOCOL_UNSUPPORTED, 21) \
103 \
104  ERROR(STUMPLESS_WINDOWS_EVENT_LOG_CLOSE_FAILURE, 22) \
105 \
106  ERROR(STUMPLESS_WINDOWS_EVENT_LOG_OPEN_FAILURE, 23) \
107 \
108  ERROR(STUMPLESS_INVALID_ENCODING, 24) \
109 \
110  ERROR(STUMPLESS_GETHOSTNAME_FAILURE, 25 ) \
111 \
116  ERROR(STUMPLESS_FUNCTION_TARGET_FAILURE, 26 ) \
117 \
122  ERROR( STUMPLESS_JOURNALD_FAILURE, 27 ) \
123 \
129  ERROR( STUMPLESS_WINDOWS_FAILURE, 28 )
130 
131 
141 enum stumpless_error_id {
143 };
144 
145 
149 struct stumpless_error {
150  enum stumpless_error_id id;
151  const char *message;
152  int code;
153  const char *code_type;
154 };
155 
189 const struct stumpless_error *
190 stumpless_get_error( void );
191 
214 stumpless_get_error_id( const struct stumpless_error *err );
215 
238 const char *
240 
258 FILE *
260 
283 bool
285 
317 void
318 stumpless_perror( const char *prefix );
319 
342 void
343 stumpless_set_error_stream( FILE *stream );
344 
345 # ifdef __cplusplus
346 } /* extern "C" */
347 # endif
348 
349 #endif /* __STUMPLESS_ERROR_H */
stumpless_error_id
stumpless_error_id
An (enum) identifier of the types of errors that might be encountered.
Definition: error.h:108
stumpless_error
Information describing an error encountered by the library.
Definition: error.h:115
STUMPLESS_GENERATE_ENUM
#define STUMPLESS_GENERATE_ENUM(NAME, VALUE)
Returns a definition of a symbol with the given name and value fit for use in an enum definition.
Definition: generator.h:33
stumpless_error::code_type
const char * code_type
a description of the error code
Definition: error.h:119
stumpless_has_error
bool stumpless_has_error(void)
True if the last call to a stumpless function encountered an error.
stumpless_perror
void stumpless_perror(const char *prefix)
Prints information about the current error to the error stream.
STUMPLESS_FOREACH_ERROR
#define STUMPLESS_FOREACH_ERROR(ERROR)
A macro to implement error id enum and error string array.
Definition: error.h:38
stumpless_get_error
const struct stumpless_error * stumpless_get_error(void)
Retrieves the error encountered by the last library call.
stumpless_set_error_stream
void stumpless_set_error_stream(FILE *stream)
Sets the stream to write errors to.
stumpless_get_error_id_string
const char * stumpless_get_error_id_string(enum stumpless_error_id id)
Gets the error string of the given error id.
stumpless_error::id
enum stumpless_error_id id
error family
Definition: error.h:116
stumpless_error::message
const char * message
specific details of the failure
Definition: error.h:117
STUMPLESS_PUBLIC_FUNCTION
#define STUMPLESS_PUBLIC_FUNCTION
Marks functions that are provided for use by the library.
Definition: config.h:31
stumpless_get_error_id
enum stumpless_error_id stumpless_get_error_id(const struct stumpless_error *err)
Gets the error id of the given error.
config.h
stumpless_error::code
int code
an error code possibly providing more information
Definition: error.h:118
stumpless_get_error_stream
FILE * stumpless_get_error_stream(void)
Gets the current stream that errors are written to.
generator.h