Line data Source code
1 : /** \file mxError.cpp
2 : * \author Jared R. Males (jaredmales@gmail.com)
3 : * \brief Function definitions for the mxlib error reporting system.
4 : * \ingroup error_handling_files
5 : *
6 : */
7 :
8 : //***********************************************************************//
9 : // Copyright 2020 Jared R. Males (jaredmales@gmail.com)
10 : //
11 : // This file is part of mxlib.
12 : //
13 : // mxlib is free software: you can redistribute it and/or modify
14 : // it under the terms of the GNU General Public License as published by
15 : // the Free Software Foundation, either version 3 of the License, or
16 : // (at your option) any later version.
17 : //
18 : // mxlib is distributed in the hope that it will be useful,
19 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 : // GNU General Public License for more details.
22 : //
23 : // You should have received a copy of the GNU General Public License
24 : // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 : //***********************************************************************//
26 :
27 : #include "error/mxErrorOld.hpp"
28 : #include <format>
29 :
30 : namespace mx
31 : {
32 :
33 0 : std::string MXE_CodeToName( int ec )
34 : {
35 :
36 0 : switch( ec )
37 : {
38 0 : case MXE_INVALIDARG:
39 0 : return MXE_INVALIDARG_NAME;
40 0 : case MXE_INVALIDCONFIG:
41 0 : return MXE_INVALIDCONFIG_NAME;
42 0 : case MXE_NOTIMPL:
43 0 : return MXE_NOTIMPL_NAME;
44 0 : case MXE_PARAMNOTSET:
45 0 : return MXE_PARAMNOTSET_NAME;
46 0 : case MXE_ENVNOTSET:
47 0 : return MXE_ENVNOTSET_NAME;
48 0 : case MXE_NOTFOUND:
49 0 : return MXE_NOTFOUND_NAME;
50 0 : case MXE_SIZEERR:
51 0 : return MXE_SIZEERR_NAME;
52 0 : case MXE_ALLOCERR:
53 0 : return MXE_ALLOCERR_NAME;
54 0 : case MXE_FREEERR:
55 0 : return MXE_FREEERR_NAME;
56 0 : case MXE_PARSEERR:
57 0 : return MXE_PARSEERR_NAME;
58 0 : case MXE_FILEOERR:
59 0 : return MXE_FILEOERR_NAME;
60 0 : case MXE_FILEWERR:
61 0 : return MXE_FILEWERR_NAME;
62 0 : case MXE_FILERERR:
63 0 : return MXE_FILERERR_NAME;
64 0 : case MXE_FILECERR:
65 0 : return MXE_FILECERR_NAME;
66 0 : case MXE_FILENOTFOUND:
67 0 : return MXE_FILENOTFOUND_NAME;
68 0 : case MXE_PROCERR:
69 0 : return MXE_PROCERR_NAME;
70 0 : case MXE_TIMEOUT:
71 0 : return MXE_TIMEOUT_NAME;
72 0 : case MXE_LIBERR:
73 0 : return MXE_LIBERR_NAME;
74 0 : case MXE_GNUPLOTERR:
75 0 : return MXE_GNUPLOTERR_NAME;
76 0 : case MXE_LAPACKERR:
77 0 : return MXE_LAPACKERR_NAME;
78 0 : default:
79 0 : return "?";
80 : }
81 : }
82 :
83 0 : std::string MXE_CodeToDescription( int ec )
84 : {
85 :
86 0 : switch( ec )
87 : {
88 0 : case MXE_INVALIDARG:
89 0 : return MXE_INVALIDARG_MSG;
90 0 : case MXE_INVALIDCONFIG:
91 0 : return MXE_INVALIDCONFIG_MSG;
92 0 : case MXE_NOTIMPL:
93 0 : return MXE_NOTIMPL_MSG;
94 0 : case MXE_PARAMNOTSET:
95 0 : return MXE_PARAMNOTSET_MSG;
96 0 : case MXE_ENVNOTSET:
97 0 : return MXE_ENVNOTSET_MSG;
98 0 : case MXE_NOTFOUND:
99 0 : return MXE_NOTFOUND_MSG;
100 0 : case MXE_SIZEERR:
101 0 : return MXE_SIZEERR_MSG;
102 0 : case MXE_ALLOCERR:
103 0 : return MXE_ALLOCERR_MSG;
104 0 : case MXE_FREEERR:
105 0 : return MXE_FREEERR_MSG;
106 0 : case MXE_PARSEERR:
107 0 : return MXE_PARSEERR_MSG;
108 0 : case MXE_FILEOERR:
109 0 : return MXE_FILEOERR_MSG;
110 0 : case MXE_FILEWERR:
111 0 : return MXE_FILEWERR_MSG;
112 0 : case MXE_FILERERR:
113 0 : return MXE_FILERERR_MSG;
114 0 : case MXE_FILECERR:
115 0 : return MXE_FILECERR_MSG;
116 0 : case MXE_FILENOTFOUND:
117 0 : return MXE_FILENOTFOUND_MSG;
118 0 : case MXE_PROCERR:
119 0 : return MXE_PROCERR_MSG;
120 0 : case MXE_TIMEOUT:
121 0 : return MXE_TIMEOUT_MSG;
122 0 : case MXE_LIBERR:
123 0 : return MXE_LIBERR_MSG;
124 0 : case MXE_GNUPLOTERR:
125 0 : return MXE_GNUPLOTERR_MSG;
126 0 : case MXE_LAPACKERR:
127 0 : return MXE_LAPACKERR_MSG;
128 0 : default:
129 0 : return "Unknown mxlib error code.";
130 : }
131 : }
132 :
133 0 : std::string errno_CodeToName( int ec )
134 : {
135 0 : switch( ec )
136 : {
137 : #ifdef E2BIG
138 0 : case E2BIG:
139 0 : return "E2BIG";
140 : #endif
141 : #ifdef EACCES
142 0 : case EACCES:
143 0 : return "EACCES";
144 : #endif
145 : #ifdef EADDRINUSE
146 0 : case EADDRINUSE:
147 0 : return "EADDRINUSE";
148 : #endif
149 : #ifdef EADDRNOTAVAIL
150 0 : case EADDRNOTAVAIL:
151 0 : return "EADDRNOTAVAIL";
152 : #endif
153 : #ifdef EAFNOSUPPORT
154 0 : case EAFNOSUPPORT:
155 0 : return "EAFNOSUPPORT";
156 : #endif
157 : #ifdef EAGAIN
158 0 : case EAGAIN:
159 : #if ( EWOULDBLOCK == EAGAIN )
160 0 : return "EAGIAN / EWOULDBLOCK";
161 : #else
162 : return "EAGAIN";
163 : #endif
164 : #endif
165 : #ifdef EALREADY
166 0 : case EALREADY:
167 0 : return "EALREADY";
168 : #endif
169 : #ifdef EBADF
170 0 : case EBADF:
171 0 : return "EBADF";
172 : #endif
173 : #ifdef EBADMSG
174 0 : case EBADMSG:
175 0 : return "EBADMSG";
176 : #endif
177 : #ifdef EBUSY
178 0 : case EBUSY:
179 0 : return "EBUSY";
180 : #endif
181 : #ifdef ECANCELED
182 0 : case ECANCELED:
183 0 : return "ECANCELED";
184 : #endif
185 : #ifdef ECHILD
186 0 : case ECHILD:
187 0 : return "ECHILD";
188 : #endif
189 : #ifdef ECONNABORTED
190 0 : case ECONNABORTED:
191 0 : return "ECONNABORTED";
192 : #endif
193 : #ifdef ECONNREFUSED
194 0 : case ECONNREFUSED:
195 0 : return "ECONNREFUSED";
196 : #endif
197 : #ifdef ECONNRESET
198 0 : case ECONNRESET:
199 0 : return "ECONNRESET";
200 : #endif
201 : #ifdef EDESTADDRREQ
202 0 : case EDESTADDRREQ:
203 0 : return "EDESTADDRREQ";
204 : #endif
205 : #ifdef EDOM
206 0 : case EDOM:
207 0 : return "EDOM";
208 : #endif
209 : #ifdef EEXIST
210 0 : case EEXIST:
211 0 : return "EEXIST";
212 : #endif
213 : #ifdef EFAULT
214 0 : case EFAULT:
215 0 : return "EFAULT";
216 : #endif
217 : #ifdef EFBIG
218 0 : case EFBIG:
219 0 : return "EFBIG";
220 : #endif
221 : #ifdef EHOSTUNREACH
222 0 : case EHOSTUNREACH:
223 0 : return "EHOSTUNREACH";
224 : #endif
225 : #ifdef EIDRM
226 0 : case EIDRM:
227 0 : return "EIDRM";
228 : #endif
229 : #ifdef EILSEQ
230 0 : case EILSEQ:
231 0 : return "EILSEQ";
232 : #endif
233 : #ifdef EINPROGRESS
234 0 : case EINPROGRESS:
235 0 : return "EINPROGRESS";
236 : #endif
237 : #ifdef EINTR
238 0 : case EINTR:
239 0 : return "EINTR";
240 : #endif
241 : #ifdef EINVAL
242 0 : case EINVAL:
243 0 : return "EINVAL";
244 : #endif
245 : #ifdef EIO
246 0 : case EIO:
247 0 : return "EIO";
248 : #endif
249 : #ifdef EISCONN
250 0 : case EISCONN:
251 0 : return "EISCONN";
252 : #endif
253 : #ifdef EISDIR
254 0 : case EISDIR:
255 0 : return "EISDIR";
256 : #endif
257 : #ifdef ELOOP
258 0 : case ELOOP:
259 0 : return "ELOOP";
260 : #endif
261 : #ifdef EMFILE
262 0 : case EMFILE:
263 0 : return "EMFILE";
264 : #endif
265 : #ifdef EMLINK
266 0 : case EMLINK:
267 0 : return "EMLINK";
268 : #endif
269 : #ifdef EMSGSIZE
270 0 : case EMSGSIZE:
271 0 : return "EMSGSIZE";
272 : #endif
273 : #ifdef ENAMETOOLONG
274 0 : case ENAMETOOLONG:
275 0 : return "ENAMETOOLONG";
276 : #endif
277 : #ifdef ENETDOWN
278 0 : case ENETDOWN:
279 0 : return "ENETDOWN";
280 : #endif
281 : #ifdef ENETRESET
282 0 : case ENETRESET:
283 0 : return "ENETRESET";
284 : #endif
285 : #ifdef ENETUNREACH
286 0 : case ENETUNREACH:
287 0 : return "ENETUNREACH";
288 : #endif
289 : #ifdef ENFILE
290 0 : case ENFILE:
291 0 : return "ENFILE";
292 : #endif
293 : #ifdef ENOBUFS
294 0 : case ENOBUFS:
295 0 : return "ENOBUFS";
296 : #endif
297 : #ifdef ENODATA
298 0 : case ENODATA:
299 0 : return "ENODATA";
300 : #endif
301 : #ifdef ENODEV
302 0 : case ENODEV:
303 0 : return "ENODEV";
304 : #endif
305 : #ifdef ENOENT
306 0 : case ENOENT:
307 0 : return "ENOENT";
308 : #endif
309 : #ifdef ENOEXEC
310 0 : case ENOEXEC:
311 0 : return "ENOEXEC";
312 : #endif
313 : #ifdef ENOLCK
314 0 : case ENOLCK:
315 0 : return "ENOLCK";
316 : #endif
317 : #ifdef ENOLINK
318 0 : case ENOLINK:
319 0 : return "ENOLINK";
320 : #endif
321 : #ifdef ENOMEM
322 0 : case ENOMEM:
323 0 : return "ENOMEM";
324 : #endif
325 : #ifdef ENOMSG
326 0 : case ENOMSG:
327 0 : return "ENOMSG";
328 : #endif
329 : #ifdef ENOPROTOOPT
330 0 : case ENOPROTOOPT:
331 0 : return "ENOPROTOOPT";
332 : #endif
333 : #ifdef ENOSPC
334 0 : case ENOSPC:
335 0 : return "ENOSPC";
336 : #endif
337 : #ifdef ENOSR
338 0 : case ENOSR:
339 0 : return "ENOSR";
340 : #endif
341 : #ifdef ENOSTR
342 0 : case ENOSTR:
343 0 : return "ENOSTR";
344 : #endif
345 : #ifdef ENOSYS
346 0 : case ENOSYS:
347 0 : return "ENOSYS";
348 : #endif
349 : #ifdef ENOTCONN
350 0 : case ENOTCONN:
351 0 : return "ENOTCONN";
352 : #endif
353 : #ifdef ENOTDIR
354 0 : case ENOTDIR:
355 0 : return "ENOTDIR";
356 : #endif
357 : #ifdef ENOTEMPTY
358 0 : case ENOTEMPTY:
359 0 : return "ENOTEMPTY";
360 : #endif
361 : #ifdef ENOTRECOVERABLE
362 0 : case ENOTRECOVERABLE:
363 0 : return "ENOTRECOVERABLE";
364 : #endif
365 : #ifdef ENOTSOCK
366 0 : case ENOTSOCK:
367 0 : return "ENOTSOCK";
368 : #endif
369 : #ifdef ENOTSUP
370 : #if ( ENOTSUP != EOPNOTSUPP )
371 : case ENOTSUP:
372 : return "ENOTSUP";
373 : #endif
374 : #endif
375 : #ifdef ENOTTY
376 0 : case ENOTTY:
377 0 : return "ENOTTY";
378 : #endif
379 : #ifdef ENXIO
380 0 : case ENXIO:
381 0 : return "ENXIO";
382 : #endif
383 : #ifdef EOPNOTSUPP
384 0 : case EOPNOTSUPP:
385 0 : return "EOPNOTSUPP";
386 : #endif
387 : #ifdef EOVERFLOW
388 0 : case EOVERFLOW:
389 0 : return "EOVERFLOW";
390 : #endif
391 : #ifdef EOWNERDEAD
392 0 : case EOWNERDEAD:
393 0 : return "EOWNERDEAD";
394 : #endif
395 : #ifdef EPERM
396 0 : case EPERM:
397 0 : return "EPERM";
398 : #endif
399 : #ifdef EPIPE
400 0 : case EPIPE:
401 0 : return "EPIPE";
402 : #endif
403 : #ifdef EPROTO
404 0 : case EPROTO:
405 0 : return "EPROTO";
406 : #endif
407 : #ifdef EPROTONOSUPPORT
408 0 : case EPROTONOSUPPORT:
409 0 : return "EPROTONOSUPPORT";
410 : #endif
411 : #ifdef EPROTOTYPE
412 0 : case EPROTOTYPE:
413 0 : return "EPROTOTYPE";
414 : #endif
415 : #ifdef ERANGE
416 0 : case ERANGE:
417 0 : return "ERANGE";
418 : #endif
419 : #ifdef EROFS
420 0 : case EROFS:
421 0 : return "EROFS";
422 : #endif
423 : #ifdef ESPIPE
424 0 : case ESPIPE:
425 0 : return "ESPIPE";
426 : #endif
427 : #ifdef ESRCH
428 0 : case ESRCH:
429 0 : return "ESRCH";
430 : #endif
431 : #ifdef ETIME
432 0 : case ETIME:
433 0 : return "ETIME";
434 : #endif
435 : #ifdef ETIMEDOUT
436 0 : case ETIMEDOUT:
437 0 : return "ETIMEDOUT";
438 : #endif
439 : #ifdef ETXTBSY
440 0 : case ETXTBSY:
441 0 : return "ETXTBSY";
442 : #endif
443 : #ifdef EWOULDBLOCK
444 : #if ( EWOULDBLOCK != EAGAIN )
445 : case EWOULDBLOCK:
446 : return "EWOULDBLOCK";
447 : #endif
448 : #endif
449 : #ifdef EXDEV
450 0 : case EXDEV:
451 0 : return "EXDEV";
452 : #endif
453 0 : default:
454 0 : return "?";
455 : }
456 : }
457 :
458 0 : std::string error_report(
459 : const std::string &source, const int &code, const std::string &file, const int &line, const std::string &expl )
460 : {
461 :
462 0 : std::string codeName, codeMessage;
463 :
464 0 : codeName = MXE_CodeToName( code );
465 0 : codeMessage = MXE_CodeToDescription( code );
466 :
467 0 : std::ostringstream s;
468 0 : s.str( "" );
469 :
470 0 : s << "An error has occured in an mxlib component.\n";
471 0 : s << " source: " << source << "\n";
472 0 : s << " code: " << codeName << "(" << code << ")\n";
473 0 : s << " code msg: " << codeMessage << "\n";
474 0 : s << " in file: " << file << "\n";
475 0 : s << " at line: " << line << "\n";
476 0 : if( expl != "" )
477 0 : s << " explanation: " << expl << "\n";
478 :
479 0 : return s.str();
480 0 : }
481 :
482 : std::string
483 0 : errno_report( const std::string &source, int ec, const std::string &file, const int &line, const std::string &expl )
484 : {
485 0 : std::string codeName, codeMessage;
486 :
487 0 : codeName = errno_CodeToName( ec );
488 0 : codeMessage = strerror( ec );
489 :
490 0 : std::ostringstream s;
491 0 : s.str( "" );
492 :
493 0 : s << "An error has occured in an mxlib component.\n";
494 0 : s << " source: " << source << "\n";
495 0 : s << " errno code: " << codeName << "(" << ec << ")\n";
496 0 : s << " code msg: " << codeMessage << "\n";
497 0 : s << " in file: " << file << "\n";
498 0 : s << " at line: " << line << "\n";
499 0 : if( expl != "" )
500 0 : s << " explanation: " << expl << "\n";
501 :
502 0 : return s.str();
503 0 : }
504 :
505 :
506 : } // namespace mx
|