dodo  0.0.1
A C++ library to create containerized Linux services
dodo::common::SystemError Class Reference

Linux system error primitive to provide a consistent interface to Linux error codes. More...

#include <systemerror.hpp>

Collaboration diagram for dodo::common::SystemError:

Public Types

enum  ErrorCode {
  ecOK = 0, ecEPERM = EPERM, ecENOENT = ENOENT, ecESRCH = ESRCH,
  ecEINTR = EINTR, ecEIO = EIO, ecENXIO = ENXIO, ecE2BIG = E2BIG,
  ecENOEXEC = ENOEXEC, ecEBADF = EBADF, ecECHILD = ECHILD, ecEAGAIN = EAGAIN,
  ecENOMEM = ENOMEM, ecEACCES = EACCES, ecEFAULT = EFAULT, ecENOTBLK = ENOTBLK,
  ecEBUSY = EBUSY, ecEEXIST = EEXIST, ecEXDEV = EXDEV, ecENODEV = ENODEV,
  ecENOTDIR = ENOTDIR, ecEISDIR = EISDIR, ecEINVAL = EINVAL, ecENFILE = ENFILE,
  ecEMFILE = EMFILE, ecENOTTY = ENOTTY, ecETXTBSY = ETXTBSY, ecEFBIG = EFBIG,
  ecENOSPC = ENOSPC, ecESPIPE = ESPIPE, ecEROFS = EROFS, ecEMLINK = EMLINK,
  ecEPIPE = EPIPE, ecEDOM = EDOM, ecERANGE = ERANGE, ecEDEADLK = EDEADLK,
  ecENAMETOOLONG = ENAMETOOLONG, ecENOLCK = ENOLCK, ecENOSYS = ENOSYS, ecENOTEMPTY = ENOTEMPTY,
  ecELOOP = ELOOP, ecEWOULDBLOCK = EWOULDBLOCK, ecENOMSG = ENOMSG, ecEIDRM = EIDRM,
  ecECHRNG = ECHRNG, ecEL2NSYNC = EL2NSYNC, ecEL3HLT = EL3HLT, ecEL3RST = EL3RST,
  ecELNRNG = ELNRNG, ecEUNATCH = EUNATCH, ecENOCSI = ENOCSI, ecEL2HLT = EL2HLT,
  ecEBADE = EBADE, ecEBADR = EBADR, ecEXFULL = EXFULL, ecENOANO = ENOANO,
  ecEBADRQC = EBADRQC, ecEBADSLT = EBADSLT, ecEDEADLOCK = EDEADLOCK, ecEBFONT = EBFONT,
  ecENOSTR = ENOSTR, ecENODATA = ENODATA, ecETIME = ETIME, ecENOSR = ENOSR,
  ecENONET = ENONET, ecENOPKG = ENOPKG, ecEREMOTE = EREMOTE, ecENOLINK = ENOLINK,
  ecEADV = EADV, ecESRMNT = ESRMNT, ecECOMM = ECOMM, ecEPROTO = EPROTO,
  ecEMULTIHOP = EMULTIHOP, ecEDOTDOT = EDOTDOT, ecEBADMSG = EBADMSG, ecEOVERFLOW = EOVERFLOW,
  ecENOTUNIQ = ENOTUNIQ, ecEBADFD = EBADFD, ecEREMCHG = EREMCHG, ecELIBACC = ELIBACC,
  ecELIBBAD = ELIBBAD, ecELIBSCN = ELIBSCN, ecELIBMAX = ELIBMAX, ecELIBEXEC = ELIBEXEC,
  ecEILSEQ = EILSEQ, ecERESTART = ERESTART, ecESTRPIPE = ESTRPIPE, ecEUSERS = EUSERS,
  ecENOTSOCK = ENOTSOCK, ecEDESTADDRREQ = EDESTADDRREQ, ecEMSGSIZE = EMSGSIZE, ecEPROTOTYPE = EPROTOTYPE,
  ecENOPROTOOPT = ENOPROTOOPT, ecEPROTONOSUPPORT = EPROTONOSUPPORT, ecESOCKTNOSUPPORT = ESOCKTNOSUPPORT, ecEOPNOTSUPP = EOPNOTSUPP,
  ecEPFNOSUPPORT = EPFNOSUPPORT, ecEAFNOSUPPORT = EAFNOSUPPORT, ecEADDRINUSE = EADDRINUSE, ecEADDRNOTAVAIL = EADDRNOTAVAIL,
  ecENETDOWN = ENETDOWN, ecENETUNREACH = ENETUNREACH, ecENETRESET = ENETRESET, ecECONNABORTED = ECONNABORTED,
  ecECONNRESET = ECONNRESET, ecENOBUFS = ENOBUFS, ecEISCONN = EISCONN, ecENOTCONN = ENOTCONN,
  ecESHUTDOWN = ESHUTDOWN, ecETOOMANYREFS = ETOOMANYREFS, ecETIMEDOUT = ETIMEDOUT, ecECONNREFUSED = ECONNREFUSED,
  ecEHOSTDOWN = EHOSTDOWN, ecEHOSTUNREACH = EHOSTUNREACH, ecEALREADY = EALREADY, ecEINPROGRESS = EINPROGRESS,
  ecESTALE = ESTALE, ecEUCLEAN = EUCLEAN, ecENOTNAM = ENOTNAM, ecENAVAIL = ENAVAIL,
  ecEISNAM = EISNAM, ecEREMOTEIO = EREMOTEIO, ecEDQUOT = EDQUOT, ecENOMEDIUM = ENOMEDIUM,
  ecEMEDIUMTYPE = EMEDIUMTYPE, ecECANCELED = ECANCELED, ecENOKEY = ENOKEY, ecEKEYEXPIRED = EKEYEXPIRED,
  ecEKEYREVOKED = EKEYREVOKED, ecEKEYREJECTED = EKEYREJECTED, ecEOWNERDEAD = EOWNERDEAD, ecENOTRECOVERABLE = ENOTRECOVERABLE,
  ecERFKILL = ERFKILL, ecEHWPOISON = EHWPOISON, ecEAI_BADFLAGS = EAI_BADFLAGS, ecEAI_NONAME = EAI_NONAME,
  ecEAI_AGAIN = EAI_AGAIN, ecEAI_FAIL = EAI_FAIL, ecEAI_NODATA = EAI_NODATA, ecEAI_FAMILY = EAI_FAMILY,
  ecEAI_SOCKTYPE = EAI_SOCKTYPE, ecEAI_SERVICE = EAI_SERVICE, ecEAI_ADDRFAMILY = EAI_ADDRFAMILY, ecEAI_MEMORY = EAI_MEMORY,
  ecEAI_SYSTEM = EAI_SYSTEM, ecEAI_OVERFLOW = EAI_OVERFLOW, ecEAI_INPROGRESS = EAI_INPROGRESS, ecEAI_CANCELED = EAI_CANCELED,
  ecEAI_NOTCANCELED = EAI_NOTCANCELED, ecEAI_ALLDONE = EAI_ALLDONE, ecEAI_INTR = EAI_INTR, ecEAI_IDN_ENCODE = EAI_IDN_ENCODE,
  ecLIBRARY_FIRST = 10000, ecSSL = 10002, ecSSL_ERROR_NONE = 10003, ecSSL_ERROR_ZERO_RETURN = 10003,
  ecSSL_ERROR_WANT_READ = 10004, ecSSL_ERROR_WANT_WRITE = 10005, ecSSL_ERROR_WANT_CONNECT = 10006, ecSSL_ERROR_WANT_ACCEPT = 10007,
  ecSSL_ERROR_WANT_X509_LOOKUP = 10008, ecSSL_ERROR_WANT_ASYNC = 10009, ecSSL_ERROR_WANT_ASYNC_JOB = 10010, ecSSL_ERROR_WANT_CLIENT_HELLO_CB = 10011,
  ecSSL_ERROR_SYSCALL = 10012, ecSSL_ERROR_PEERVERIFICATION = 10013
}
 Enumerate mimicking Linux error codes, integrates the EAI (addrinfo) ranges of errors. More...
 

Public Member Functions

 SystemError ()
 Construct default with ecOK. More...
 
 SystemError (ErrorCode e)
 Construct from ErrorCode enumerate. More...
 
 SystemError (int e)
 Construct from system error code. More...
 
std::string asString () const
 Get the system error string. More...
 
bool ok () const
 Returns true when this->errorcode_ == ecOK. More...
 
 operator int () const
 Cast this SystemError to an int by taking error code_. More...
 
bool operator!= (ErrorCode e) const
 Compare this SystemError to the ErrorCode e. More...
 
bool operator!= (int e) const
 Compare this SystemError to the system error e. More...
 
bool operator!= (SystemError e) const
 Compare this SystemError to the SystemError e. More...
 
SystemErroroperator= (ErrorCode e)
 Assign ErrorCode e. More...
 
SystemErroroperator= (int e)
 Assign system error e. More...
 
SystemErroroperator= (SystemError e)
 Assign SystemError e. More...
 
bool operator== (const SystemError &e) const
 Compare this SystemError to the SystemError e. More...
 
bool operator== (ErrorCode e) const
 Compare this SystemError to the ErrorCode e. More...
 

Static Public Member Functions

static std::string libstrerror (SystemError error)
 Translate SystemErrors in library range. More...
 

Private Attributes

ErrorCode errorcode_
 Enumerate representation of the system error code. More...
 

Detailed Description

Linux system error primitive to provide a consistent interface to Linux error codes.

The [[nodiscard]] attribute causes the compiler to issue a warning in case a SystemError is produced as r-value but not assigned to an l-value - encouraging more robust code by pinpointing omitted error checking.

SystemError error1; // set to ecOK
SystemError error2( SystemError::ecECONNREFUSED ); // set to ECONNREFUSED
error1 == error2; // false
error1 != error2; // true
error1 == SystemError::ecECONNREFUSED; // false
error2 == SystemError::ecECONNREFUSED; // true
int i = error1; // error1 cast to int=ecOK
error1 = SystemError::ecEBADF // error1 set to SystemError::ecEBADF

Definition at line 53 of file systemerror.hpp.

Member Enumeration Documentation

◆ ErrorCode

Enumerate mimicking Linux error codes, integrates the EAI (addrinfo) ranges of errors.

Enumerator
ecOK 

0 Not an error, success

ecEPERM 

1 Operation not permitted

ecENOENT 

2 No such file or directory

ecESRCH 

3 No such process

ecEINTR 

4 Interrupted system call

ecEIO 

5 I/O error

ecENXIO 

6 No such device or address

ecE2BIG 

7 Argument list too long

ecENOEXEC 

8 Exec format error

ecEBADF 

9 Bad file number

ecECHILD 

10 No child processes

ecEAGAIN 

11 Try again

ecENOMEM 

12 Out of memory

ecEACCES 

13 Permission denied

ecEFAULT 

14 Bad address

ecENOTBLK 

15 Block device required

ecEBUSY 

16 Device or resource busy

ecEEXIST 

17 File exists

ecEXDEV 

18 Cross-device link

ecENODEV 

19 No such device

ecENOTDIR 

20 Not a directory

ecEISDIR 

21 Is a directory

ecEINVAL 

22 Invalid argument

ecENFILE 

23 File table overflow

ecEMFILE 

24 Too many open files

ecENOTTY 

25 Not a typewriter

ecETXTBSY 

26 Text file busy

ecEFBIG 

27 File too large

ecENOSPC 

28 No space left on device

ecESPIPE 

29 Illegal seek

ecEROFS 

30 Read-only file system

ecEMLINK 

31 Too many links

ecEPIPE 

32 Broken pipe

ecEDOM 

33 Math argument out of domain of function

ecERANGE 

34 Math result not representable

ecEDEADLK 

35 Resource deadlock would occur

ecENAMETOOLONG 

36 File name too long

ecENOLCK 

37 No record locks available

ecENOSYS 

38 Invalid system call number

ecENOTEMPTY 

39 Directory not empty

ecELOOP 

40 Too many symbolic links encountered

ecEWOULDBLOCK 

41 Operation would block

ecENOMSG 

42 No message of desired type

ecEIDRM 

43 Identifier removed

ecECHRNG 

44 Channel number out of range

ecEL2NSYNC 

45 Level 2 not synchronized

ecEL3HLT 

46 Level 3 halted

ecEL3RST 

47 Level 3 reset

ecELNRNG 

48 Link number out of range

ecEUNATCH 

49 Protocol driver not attached

ecENOCSI 

50 No CSI structure available

ecEL2HLT 

51 Level 2 halted

ecEBADE 

52 Invalid exchange

ecEBADR 

53 Invalid request descriptor

ecEXFULL 

54 Exchange full

ecENOANO 

55 No anode

ecEBADRQC 

56 Invalid request code

ecEBADSLT 

57 Invalid slot

ecEDEADLOCK 

58 EDEADLK

ecEBFONT 

59 Bad font file format

ecENOSTR 

60 Device not a stream

ecENODATA 

61 No data available

ecETIME 

62 Timer expired

ecENOSR 

63 Out of streams resources

ecENONET 

64 Machine is not on the network

ecENOPKG 

65 Package not installed

ecEREMOTE 

66 Object is remote

ecENOLINK 

67 Link has been severed

ecEADV 

68 Advertise error

ecESRMNT 

69 Srmount error

ecECOMM 

70 Communication error on send

ecEPROTO 

71 Protocol error

ecEMULTIHOP 

72 Multihop attempted

ecEDOTDOT 

73 RFS specific error

ecEBADMSG 

74 Not a data message

ecEOVERFLOW 

75 Value too large for defined data type

ecENOTUNIQ 

76 Name not unique on network

ecEBADFD 

77 File descriptor in bad state

ecEREMCHG 

78 Remote address changed

ecELIBACC 

79 Can not access a needed shared library

ecELIBBAD 

80 Accessing a corrupted shared library

ecELIBSCN 

81 .lib section in a.out corrupted

ecELIBMAX 

82 Attempting to link in too many shared libraries

ecELIBEXEC 

83 Cannot exec a shared library directly

ecEILSEQ 

84 Illegal byte sequence

ecERESTART 

85 Interrupted system call should be restarted

ecESTRPIPE 

86 Streams pipe error

ecEUSERS 

87 Too many users

ecENOTSOCK 

88 Socket operation on non-socket

ecEDESTADDRREQ 

89 Destination address required

ecEMSGSIZE 

90 Message too long

ecEPROTOTYPE 

91 Protocol wrong type for socket

ecENOPROTOOPT 

92 Protocol not available

ecEPROTONOSUPPORT 

93 Protocol not supported

ecESOCKTNOSUPPORT 

94 Socket type not supported

ecEOPNOTSUPP 

95 Operation not supported on transport endpoint

ecEPFNOSUPPORT 

96 Protocol family not supported

ecEAFNOSUPPORT 

97 Address family not supported by protocol

ecEADDRINUSE 

98 Address already in use

ecEADDRNOTAVAIL 

99 Cannot assign requested address

ecENETDOWN 

100 Network is down

ecENETUNREACH 

101 Network is unreachable

ecENETRESET 

102 Network dropped connection because of reset

ecECONNABORTED 

103 Software caused connection abort

ecECONNRESET 

104 Connection reset by peer

ecENOBUFS 

105 No buffer space available

ecEISCONN 

106 Transport endpoint is already connected

ecENOTCONN 

107 Transport endpoint is not connected

ecESHUTDOWN 

108 Cannot send after transport endpoint shutdown

ecETOOMANYREFS 

109 Too many references: cannot splice

ecETIMEDOUT 

110 Connection timed out

ecECONNREFUSED 

111 Connection refused

ecEHOSTDOWN 

112 Host is down

ecEHOSTUNREACH 

113 No route to host

ecEALREADY 

114 Operation already in progress

ecEINPROGRESS 

115 Operation now in progress

ecESTALE 

116 Stale file handle

ecEUCLEAN 

117 Structure needs cleaning

ecENOTNAM 

118 Not a XENIX named type file

ecENAVAIL 

119 No XENIX semaphores available

ecEISNAM 

120 Is a named type file

ecEREMOTEIO 

121 Remote I/O error

ecEDQUOT 

122 Quota exceeded

ecENOMEDIUM 

123 No medium found

ecEMEDIUMTYPE 

124 Wrong medium type

ecECANCELED 

125 Operation Canceled

ecENOKEY 

126 Required key not available

ecEKEYEXPIRED 

127 Key has expired

ecEKEYREVOKED 

128 Key has been revoked

ecEKEYREJECTED 

129 Key was rejected by service

ecEOWNERDEAD 

130 Owner died

ecENOTRECOVERABLE 

131 State not recoverable

ecERFKILL 

132 Operation not possible due to RF-kill

ecEHWPOISON 

133 Memory page has hardware error

ecEAI_BADFLAGS 

-1 Invalid value for ‘ai_flags’ field.


ecEAI_NONAME 

-2 NAME or SERVICE is unknown.


ecEAI_AGAIN 

-3 Temporary failure in name resolution.


ecEAI_FAIL 

-4 Non-recoverable failure in name res.


ecEAI_NODATA 

-5 No address associated with NAME.


ecEAI_FAMILY 

-6 ai_family not supported.


ecEAI_SOCKTYPE 

-7 ai_socktype not supported.


ecEAI_SERVICE 

-8 SERVICE not supported for ‘ai_socktype’.


ecEAI_ADDRFAMILY 

-9 Address family for NAME not supported.


ecEAI_MEMORY 

-10 Memory allocation failure.


ecEAI_SYSTEM 

-11 System error returned in ‘errno’.


ecEAI_OVERFLOW 

-12 Argument buffer overflow.


ecEAI_INPROGRESS 

-100 Processing request in progress.


ecEAI_CANCELED 

-101 Request canceled.


ecEAI_NOTCANCELED 

-102 Request not canceled.


ecEAI_ALLDONE 

-103 All requests done.


ecEAI_INTR 

-104 Interrupted by a signal.


ecEAI_IDN_ENCODE 

-105 IDN encoding failed.


ecLIBRARY_FIRST 

10000 Marker, library error codes from here.

ecSSL 

10002 SSL exception

ecSSL_ERROR_NONE 

10003 SSL_ERROR_NONE

ecSSL_ERROR_ZERO_RETURN 

10003 SSL_ERROR_ZERO_RETURN

ecSSL_ERROR_WANT_READ 

10004 SSL_ERROR_WANT_READ

ecSSL_ERROR_WANT_WRITE 

10005 SSL_ERROR_WANT_WRITE

ecSSL_ERROR_WANT_CONNECT 

10006 SSL_ERROR_WANT_CONNECT

ecSSL_ERROR_WANT_ACCEPT 

10007 SSL_ERROR_WANT_ACCEPT

ecSSL_ERROR_WANT_X509_LOOKUP 

10008 SSL_ERROR_WANT_X509_LOOKUP

ecSSL_ERROR_WANT_ASYNC 

10009 SSL_ERROR_WANT_ASYNC

ecSSL_ERROR_WANT_ASYNC_JOB 

10010 SSL_ERROR_WANT_ASYNC_JOB

ecSSL_ERROR_WANT_CLIENT_HELLO_CB 

10011 SSL_ERROR_WANT_CLIENT_HELLO_CB

ecSSL_ERROR_SYSCALL 

10012 SSL_ERROR_SYSCALL

ecSSL_ERROR_PEERVERIFICATION 

10013 When peer verification failed

Definition at line 59 of file systemerror.hpp.

Constructor & Destructor Documentation

◆ SystemError() [1/3]

dodo::common::SystemError::SystemError ( )
inline

Construct default with ecOK.

Definition at line 236 of file systemerror.hpp.

◆ SystemError() [2/3]

dodo::common::SystemError::SystemError ( ErrorCode  e)
inline

Construct from ErrorCode enumerate.

Parameters
eThe ErrorCode to assign.

Definition at line 242 of file systemerror.hpp.

◆ SystemError() [3/3]

dodo::common::SystemError::SystemError ( int  e)
inline

Construct from system error code.

Parameters
eThe int error to assign.

Definition at line 248 of file systemerror.hpp.

Member Function Documentation

◆ asString()

std::string dodo::common::SystemError::asString ( ) const
inline

Get the system error string.

Returns
The system error string.

Definition at line 322 of file systemerror.hpp.

Referenced by dodo::network::protocol::http::HTTPFragment::ParseResult::asString(), and dodo::network::TCPConnectionData::readBuffer().

Here is the caller graph for this function:

◆ libstrerror()

static std::string dodo::common::SystemError::libstrerror ( SystemError  error)
inlinestatic

Translate SystemErrors in library range.

Parameters
errorThe SystemError to translate.
Returns
The error string.

Definition at line 343 of file systemerror.hpp.

References ecSSL, ecSSL_ERROR_PEERVERIFICATION, and ecSSL_ERROR_SYSCALL.

◆ ok()

bool dodo::common::SystemError::ok ( ) const
inline

Returns true when this->errorcode_ == ecOK.

Returns
True when this->errorcode_ == ecOK

Definition at line 254 of file systemerror.hpp.

Referenced by dodo::network::protocol::http::HTTPRequest::send(), and dodo::network::protocol::http::HTTPResponse::send().

Here is the caller graph for this function:

◆ operator int()

dodo::common::SystemError::operator int ( ) const
inline

Cast this SystemError to an int by taking error code_.

Returns
The int cast to.

Definition at line 316 of file systemerror.hpp.

◆ operator!=() [1/3]

bool dodo::common::SystemError::operator!= ( ErrorCode  e) const
inline

Compare this SystemError to the ErrorCode e.

Parameters
eThe ErrorCode to compare to.
Returns
true when unequal.

Definition at line 268 of file systemerror.hpp.

◆ operator!=() [2/3]

bool dodo::common::SystemError::operator!= ( int  e) const
inline

Compare this SystemError to the system error e.

Parameters
eThe int to compare to.
Returns
true when unequal.

Definition at line 261 of file systemerror.hpp.

◆ operator!=() [3/3]

bool dodo::common::SystemError::operator!= ( SystemError  e) const
inline

Compare this SystemError to the SystemError e.

Parameters
eThe SystemError to compare to.
Returns
true when unequal.

Definition at line 275 of file systemerror.hpp.

References errorcode_.

◆ operator=() [1/3]

SystemError& dodo::common::SystemError::operator= ( ErrorCode  e)
inline

Assign ErrorCode e.

Parameters
eThe ErrorCode to assign
Returns
This SystemError

Definition at line 303 of file systemerror.hpp.

◆ operator=() [2/3]

SystemError& dodo::common::SystemError::operator= ( int  e)
inline

Assign system error e.

Parameters
eThe int error to assign
Returns
This SystemError

Definition at line 296 of file systemerror.hpp.

◆ operator=() [3/3]

SystemError& dodo::common::SystemError::operator= ( SystemError  e)
inline

Assign SystemError e.

Parameters
eThe SystemError to assign
Returns
This SystemError

Definition at line 310 of file systemerror.hpp.

References errorcode_.

◆ operator==() [1/2]

bool dodo::common::SystemError::operator== ( const SystemError e) const
inline

Compare this SystemError to the SystemError e.

Parameters
eThe SystemError to compare to.
Returns
true when equal.

Definition at line 289 of file systemerror.hpp.

References errorcode_.

◆ operator==() [2/2]

bool dodo::common::SystemError::operator== ( ErrorCode  e) const
inline

Compare this SystemError to the ErrorCode e.

Parameters
eThe error to compare to.
Returns
true when equal.

Definition at line 282 of file systemerror.hpp.

Field Documentation

◆ errorcode_

ErrorCode dodo::common::SystemError::errorcode_
private

Enumerate representation of the system error code.

Definition at line 359 of file systemerror.hpp.

Referenced by operator!=(), operator=(), and operator==().


The documentation for this class was generated from the following file:
dodo::common::SystemError::ecECONNREFUSED
@ ecECONNREFUSED
111 Connection refused
Definition: systemerror.hpp:171
dodo::common::SystemError::SystemError
SystemError()
Construct default with ecOK.
Definition: systemerror.hpp:236
dodo::common::SystemError::ecEBADF
@ ecEBADF
9 Bad file number
Definition: systemerror.hpp:69