00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00016 #include <ders/error.hpp>
00017 #include <errno.h>
00018 #include <ders/text_buf.hpp>
00019
00020 namespace {
00021
00022 const char* error_strs[]={
00023 "No error",
00024 "Argument list too long",
00025 "Permission denied",
00026 "Address in use",
00027 "Address not available",
00028 "Address family not supported",
00029 "Resource unavailable, try again",
00030 "Connection already in progress",
00031 "Bad file descriptor",
00032 "Bad message",
00033 "Device or resource busy",
00034 "Operation canceled",
00035 "No child processes",
00036 "Connection aborted",
00037 "Connection refused",
00038 "Connection reset",
00039 "Resource deadlock would occur",
00040 "Destination address required",
00041 "Mathematics argument out of domain of function",
00042 "Reserved (EDQUOT)",
00043 "File exists",
00044 "Bad address",
00045 "File too large",
00046 "Host is unreachable",
00047 "Identifier removed",
00048 "Illegal byte sequence",
00049 "Operation in progress",
00050 "Interrupted function",
00051 "Invalid argument",
00052 "I/O error",
00053 "Socket is connected",
00054 "Is a directory",
00055 "Too many levels of symbolic links",
00056 "Too many open files",
00057 "Too many links",
00058 "Message too large",
00059 "Reserved (EMULTIHOP)",
00060 "Filename too long",
00061 "Network is down ",
00062 "Connection aborted by network",
00063 "Network unreachable",
00064 "Too many files open in system",
00065 "No buffer space available",
00066 "No message is available on the STREAM head read queue",
00067 "No such device",
00068 "No such file or directory",
00069 "Executable file format error",
00070 "No locks available",
00071 "Reserved (ENOLINK)",
00072 "Not enough space",
00073 "No message of the desired type",
00074 "Protocol not available",
00075 "No space left on device",
00076 "No STREAM resources",
00077 "Not a STREAM",
00078 "Function not supported",
00079 "The socket is not connected",
00080 "Not a directory",
00081 "Directory not empty",
00082 "Not a socket",
00083 "Not supported",
00084 "Inappropriate I/O control operation",
00085 "No such device or address",
00086 "Operation not supported on socket",
00087 "Value too large to be stored in data type",
00088 "Operation not permitted",
00089 "Broken pipe",
00090 "Protocol error",
00091 "Protocol not supported",
00092 "Protocol wrong type for socket",
00093 "Result too large",
00094 "Read-only file system",
00095 "Invalid seek",
00096 "No such process",
00097 "Reserved (ESTALE)",
00098 "Stream ioctl() timeout",
00099 "Connection timed out",
00100 "Text file busy",
00101 "Unknown error",
00102 "Operation would block",
00103 "Cross-device link"
00104 };
00105
00106 }
00107
00108 namespace ders {
00109
00110 sh_text error_message(mem_pool& mp, error err)
00111 {
00112 assert(unsigned(err)<sizeof(error_strs)/sizeof(*error_strs));
00113 return nt(mp, error_strs[err]);
00114 }
00115
00116 error convert_errno(int val)
00117 {
00118 switch (val) {
00119 case 0: return ezero;
00120 #ifdef E2BIG
00121 case E2BIG: return e2big;
00122 #endif
00123 #ifdef EACCES
00124 case EACCES: return eacces;
00125 #endif
00126 #ifdef EADDRINUSE
00127 case EADDRINUSE: return eaddrinuse;
00128 #endif
00129 #ifdef EADDRNOTAVAIL
00130 case EADDRNOTAVAIL: return eaddrnotavail;
00131 #endif
00132 #ifdef EAFNOSUPPORT
00133 case EAFNOSUPPORT: return eafnosupport;
00134 #endif
00135 #ifdef EAGAIN
00136 case EAGAIN: return eagain;
00137 #endif
00138 #ifdef EALREADY
00139 case EALREADY: return ealready;
00140 #endif
00141 #ifdef EBADF
00142 case EBADF: return ebadf;
00143 #endif
00144 #ifdef EBADMSG
00145 case EBADMSG: return ebadmsg;
00146 #endif
00147 #ifdef EBUSY
00148 case EBUSY: return ebusy;
00149 #endif
00150 #ifdef ECANCELED
00151 case ECANCELED: return ecanceled;
00152 #endif
00153 #ifdef ECHILD
00154 case ECHILD: return echild;
00155 #endif
00156 #ifdef ECONNABORTED
00157 case ECONNABORTED: return econnaborted;
00158 #endif
00159 #ifdef ECONNREFUSED
00160 case ECONNREFUSED: return econnrefused;
00161 #endif
00162 #ifdef ECONNRESET
00163 case ECONNRESET: return econnreset;
00164 #endif
00165 #ifdef EDEADLK
00166 case EDEADLK: return edeadlk;
00167 #endif
00168 #ifdef EDESTADDRREQ
00169 case EDESTADDRREQ: return edestaddrreq;
00170 #endif
00171 #ifdef EDOM
00172 case EDOM: return edom;
00173 #endif
00174 #ifdef EDQUOT
00175 case EDQUOT: return edquot;
00176 #endif
00177 #ifdef EEXIST
00178 case EEXIST: return eexist;
00179 #endif
00180 #ifdef EFAULT
00181 case EFAULT: return efault;
00182 #endif
00183 #ifdef EFBIG
00184 case EFBIG: return efbig;
00185 #endif
00186 #ifdef EHOSTUNREACH
00187 case EHOSTUNREACH: return ehostunreach;
00188 #endif
00189 #ifdef EIDRM
00190 case EIDRM: return eidrm;
00191 #endif
00192 #ifdef EILSEQ
00193 case EILSEQ: return eilseq;
00194 #endif
00195 #ifdef EINPROGRESS
00196 case EINPROGRESS: return einprogress;
00197 #endif
00198 #ifdef EINTR
00199 case EINTR: return eintr;
00200 #endif
00201 #ifdef EINVAL
00202 case EINVAL: return einval;
00203 #endif
00204 #ifdef EIO
00205 case EIO: return eio;
00206 #endif
00207 #ifdef EISCONN
00208 case EISCONN: return eisconn;
00209 #endif
00210 #ifdef EISDIR
00211 case EISDIR: return eisdir;
00212 #endif
00213 #ifdef ELOOP
00214 case ELOOP: return eloop;
00215 #endif
00216 #ifdef EMFILE
00217 case EMFILE: return emfile;
00218 #endif
00219 #ifdef EMLINK
00220 case EMLINK: return emlink;
00221 #endif
00222 #ifdef EMSGSIZE
00223 case EMSGSIZE: return emsgsize;
00224 #endif
00225 #ifdef EMULTIHOP
00226 case EMULTIHOP: return emultihop;
00227 #endif
00228 #ifdef ENAMETOOLONG
00229 case ENAMETOOLONG: return enametoolong;
00230 #endif
00231 #ifdef ENETDOWN
00232 case ENETDOWN: return enetdown;
00233 #endif
00234 #ifdef ENETRESET
00235 case ENETRESET: return enetreset;
00236 #endif
00237 #ifdef ENETUNREACH
00238 case ENETUNREACH: return enetunreach;
00239 #endif
00240 #ifdef ENFILE
00241 case ENFILE: return enfile;
00242 #endif
00243 #ifdef ENOBUFS
00244 case ENOBUFS: return enobufs;
00245 #endif
00246 #ifdef ENODATA
00247 case ENODATA: return enodata;
00248 #endif
00249 #ifdef ENODEV
00250 case ENODEV: return enodev;
00251 #endif
00252 #ifdef ENOENT
00253 case ENOENT: return enoent;
00254 #endif
00255 #ifdef ENOEXEC
00256 case ENOEXEC: return enoexec;
00257 #endif
00258 #ifdef ENOLCK
00259 case ENOLCK: return enolck;
00260 #endif
00261 #ifdef ENOLINK
00262 case ENOLINK: return enolink;
00263 #endif
00264 #ifdef ENOMEM
00265 case ENOMEM: return enomem;
00266 #endif
00267 #ifdef ENOMSG
00268 case ENOMSG: return enomsg;
00269 #endif
00270 #ifdef ENOPROTOOPT
00271 case ENOPROTOOPT: return enoprotoopt;
00272 #endif
00273 #ifdef ENOSPC
00274 case ENOSPC: return enospc;
00275 #endif
00276 #ifdef ENOSR
00277 case ENOSR: return enosr;
00278 #endif
00279 #ifdef ENOSTR
00280 case ENOSTR: return enostr;
00281 #endif
00282 #ifdef ENOSYS
00283 case ENOSYS: return enosys;
00284 #endif
00285 #ifdef ENOTCONN
00286 case ENOTCONN: return enotconn;
00287 #endif
00288 #ifdef ENOTDIR
00289 case ENOTDIR: return enotdir;
00290 #endif
00291 #ifdef ENOTEMPTY
00292 case ENOTEMPTY: return enotempty;
00293 #endif
00294 #ifdef ENOTSOCK
00295 case ENOTSOCK: return enotsock;
00296 #endif
00297 #if defined(ENOTSUP) && ENOTSUP!=EOPNOTSUPP
00298 case ENOTSUP: return enotsup;
00299 #endif
00300 #ifdef ENOTTY
00301 case ENOTTY: return enotty;
00302 #endif
00303 #ifdef ENXIO
00304 case ENXIO: return enxio;
00305 #endif
00306 #ifdef EOPNOTSUPP
00307 case EOPNOTSUPP: return eopnotsupp;
00308 #endif
00309 #ifdef EOVERFLOW
00310 case EOVERFLOW: return eoverflow;
00311 #endif
00312 #ifdef EPERM
00313 case EPERM: return eperm;
00314 #endif
00315 #ifdef EPIPE
00316 case EPIPE: return epipe;
00317 #endif
00318 #ifdef EPROTO
00319 case EPROTO: return eproto;
00320 #endif
00321 #ifdef EPROTONOSUPPORT
00322 case EPROTONOSUPPORT: return eprotonosupport;
00323 #endif
00324 #ifdef EPROTOTYPE
00325 case EPROTOTYPE: return eprototype;
00326 #endif
00327 #ifdef ERANGE
00328 case ERANGE: return erange;
00329 #endif
00330 #ifdef EROFS
00331 case EROFS: return erofs;
00332 #endif
00333 #ifdef ESPIPE
00334 case ESPIPE: return espipe;
00335 #endif
00336 #ifdef ESRCH
00337 case ESRCH: return esrch;
00338 #endif
00339 #ifdef ESTALE
00340 case ESTALE: return estale;
00341 #endif
00342 #ifdef ETIME
00343 case ETIME: return etime;
00344 #endif
00345 #ifdef ETIMEDOUT
00346 case ETIMEDOUT: return etimedout;
00347 #endif
00348 #ifdef ETXTBSY
00349 case ETXTBSY: return etxtbsy;
00350 #endif
00351 #if defined(EWOULDBLOCK) && EWOULDBLOCK!=EAGAIN
00352 case EWOULDBLOCK: return ewouldblock;
00353 #endif
00354 #ifdef EXDEV
00355 case EXDEV: return exdev;
00356 #endif
00357 default: return eunkn;
00358 }
00359 }
00360
00361 shException newErrorException(mem_pool& mp, const FileLine& loc, const ch_rng&
00362 msg, error err)
00363 {
00364 return newErrorException(loc, msg, err, shException(mp, 0));
00365 }
00366
00367 shException newErrorException(const FileLine& loc, const ch_rng& msg, error err,
00368 shException nest)
00369 {
00370 mp_newbuf<ErrorException> buf(nest.pool());
00371 return shException(buf.pool(), buf.rls(::new(buf.get()) ErrorException(loc,
00372 msg, err, nest)));
00373 }
00374
00375 ErrorException::ErrorException(const FileLine& loc, const ch_rng& msg, error
00376 err, shException nest) : Exception(loc, msg, nest), errorCode(err)
00377 {
00378 }
00379
00380 sh_text ErrorException::getClassName() const
00381 {
00382 return nt(message.pool(), "ders::ErrorException");
00383 }
00384
00385 sh_text ErrorException::toText() const
00386 {
00387 return text_buf(getClassName())+" ["+location.file+":"+location.line+
00388 "], errorCode="+errorCode+":\""+error_message(message.pool(), errorCode)+
00389 "\", message: "+message;
00390 }
00391
00392 }
00393