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