001: /*
002: * TclPosixException.java --
003: *
004: * This file implements the TclPosixException class, used to report posix
005: * errors in Tcl scripts.
006: *
007: * Copyright (c) 1997 Sun Microsystems, Inc.
008: *
009: * See the file "license.terms" for information on usage and
010: * redistribution of this file, and for a DISCLAIMER OF ALL
011: * WARRANTIES.
012: *
013: * RCS: @(#) $Id: TclPosixException.java,v 1.2 2001/11/22 00:08:36 mdejong Exp $
014: *
015: */
016:
017: package tcl.lang;
018:
019: /*
020: * This class implements exceptions used to report posix errors in Tcl scripts.
021: */
022:
023: class TclPosixException extends TclException {
024:
025: static final int EPERM = 1; /* Operation not permitted */
026: static final int ENOENT = 2; /* No such file or directory */
027: static final int ESRCH = 3; /* No such process */
028: static final int EINTR = 4; /* Interrupted system call */
029: static final int EIO = 5; /* Input/output error */
030: static final int ENXIO = 6; /* Device not configured */
031: static final int E2BIG = 7; /* Argument list too long */
032: static final int ENOEXEC = 8; /* Exec format error */
033: static final int EBADF = 9; /* Bad file descriptor */
034: static final int ECHILD = 10; /* No child processes */
035: static final int EDEADLK = 11; /* Resource deadlock avoided */
036: /* 11 was EAGAIN */
037: static final int ENOMEM = 12; /* Cannot allocate memory */
038: static final int EACCES = 13; /* Permission denied */
039: static final int EFAULT = 14; /* Bad address */
040: static final int ENOTBLK = 15; /* Block device required */
041: static final int EBUSY = 16; /* Device busy */
042: static final int EEXIST = 17; /* File exists */
043: static final int EXDEV = 18; /* Cross-device link */
044: static final int ENODEV = 19; /* Operation not supported by device */
045: static final int ENOTDIR = 20; /* Not a directory */
046: static final int EISDIR = 21; /* Is a directory */
047: static final int EINVAL = 22; /* Invalid argument */
048: static final int ENFILE = 23; /* Too many open files in system */
049: static final int EMFILE = 24; /* Too many open files */
050: static final int ENOTTY = 25; /* Inappropriate ioctl for device */
051: static final int ETXTBSY = 26; /* Text file busy */
052: static final int EFBIG = 27; /* File too large */
053: static final int ENOSPC = 28; /* No space left on device */
054: static final int ESPIPE = 29; /* Illegal seek */
055: static final int EROFS = 30; /* Read-only file system */
056: static final int EMLINK = 31; /* Too many links */
057: static final int EPIPE = 32; /* Broken pipe */
058: static final int EDOM = 33; /* Numerical argument out of domain */
059: static final int ERANGE = 34; /* Result too large */
060: static final int EAGAIN = 35; /* Resource temporarily unavailable */
061: static final int EWOULDBLOCK = EAGAIN; /* Operation would block */
062: static final int EINPROGRESS = 36; /* Operation now in progress */
063: static final int EALREADY = 37; /* Operation already in progress */
064: static final int ENOTSOCK = 38; /* Socket operation on non-socket */
065: static final int EDESTADDRREQ = 39; /* Destination address required */
066: static final int EMSGSIZE = 40; /* Message too long */
067: static final int EPROTOTYPE = 41; /* Protocol wrong type for socket */
068: static final int ENOPROTOOPT = 42; /* Protocol not available */
069: static final int EPROTONOSUPPORT = 43; /* Protocol not supported */
070: static final int ESOCKTNOSUPPORT = 44; /* Socket type not supported */
071: static final int EOPNOTSUPP = 45; /* Operation not supported on socket */
072: static final int EPFNOSUPPORT = 46; /* Protocol family not supported */
073: static final int EAFNOSUPPORT = 47; /* Address family not supported by
074: /* protocol family */
075: static final int EADDRINUSE = 48; /* Address already in use */
076: static final int EADDRNOTAVAIL = 49; /* Can't assign requested
077: /* address */
078: static final int ENETDOWN = 50; /* Network is down */
079: static final int ENETUNREACH = 51; /* Network is unreachable */
080: static final int ENETRESET = 52; /* Network dropped connection on reset */
081: static final int ECONNABORTED = 53; /* Software caused connection abort */
082: static final int ECONNRESET = 54; /* Connection reset by peer */
083: static final int ENOBUFS = 55; /* No buffer space available */
084: static final int EISCONN = 56; /* Socket is already connected */
085: static final int ENOTCONN = 57; /* Socket is not connected */
086: static final int ESHUTDOWN = 58; /* Can't send after socket shutdown */
087: static final int ETOOMANYREFS = 59; /* Too many references: can't splice */
088: static final int ETIMEDOUT = 60; /* Connection timed out */
089: static final int ECONNREFUSED = 61; /* Connection refused */
090: static final int ELOOP = 62; /* Too many levels of symbolic links */
091: static final int ENAMETOOLONG = 63; /* File name too long */
092: static final int EHOSTDOWN = 64; /* Host is down */
093: static final int EHOSTUNREACH = 65; /* No route to host */
094: static final int ENOTEMPTY = 66; /* Directory not empty */
095: static final int EPROCLIM = 67; /* Too many processes */
096: static final int EUSERS = 68; /* Too many users */
097: static final int EDQUOT = 69; /* Disc quota exceeded */
098: static final int ESTALE = 70; /* Stale NFS file handle */
099: static final int EREMOTE = 71; /* Too many levels of remote in path */
100: static final int EBADRPC = 72; /* RPC struct is bad */
101: static final int ERPCMISMATCH = 73; /* RPC version wrong */
102: static final int EPROGUNAVAIL = 74; /* RPC prog. not avail */
103: static final int EPROGMISMATCH = 75; /* Program version wrong */
104: static final int EPROCUNAVAIL = 76; /* Bad procedure for program */
105: static final int ENOLCK = 77; /* No locks available */
106: static final int ENOSYS = 78; /* Function not implemented */
107: static final int EFTYPE = 79; /* Inappropriate file type or format */
108:
109: /*
110: *----------------------------------------------------------------------
111: *
112: * TclPosixException --
113: *
114: * Creates a TclException with the appropiate Tcl error message for posix
115: * error, and sets the interp's error code to a 3 element list
116: * (eg. {"posix" "eexist" {file already exists}}). If the appendPosixMsg
117: * flag is true, then append the last element to the Tcl error message.
118: *
119: * Side effects:
120: * None.
121: *
122: *----------------------------------------------------------------------
123: */
124:
125: public TclPosixException(Interp interp, // Interpreter for error report.
126: int errno, // Code of posix error.
127: String errorMsg) // Message to ouput to user.
128: throws TclException {
129: super (TCL.ERROR);
130:
131: String msg = getPosixMsg(errno);
132:
133: TclObject threeEltListObj = TclList.newInstance();
134: TclList.append(interp, threeEltListObj, TclString
135: .newInstance("POSIX"));
136: TclList.append(interp, threeEltListObj, TclString
137: .newInstance(getPosixId(errno)));
138: TclList.append(interp, threeEltListObj, TclString
139: .newInstance(msg));
140:
141: interp.setErrorCode(threeEltListObj);
142:
143: if (interp != null) {
144: interp.setResult(errorMsg);
145: }
146: }
147:
148: public TclPosixException(Interp interp, // Interpreter for error report.
149: int errno, // Code of posix error.
150: boolean appendPosixMsg, // Tells whether to append posix
151: // message to "errorMsg".
152: String errorMsg) // Message to ouput to user.
153: throws TclException {
154: super (TCL.ERROR);
155:
156: String msg = getPosixMsg(errno);
157:
158: TclObject threeEltListObj = TclList.newInstance();
159: TclList.append(interp, threeEltListObj, TclString
160: .newInstance("POSIX"));
161: TclList.append(interp, threeEltListObj, TclString
162: .newInstance(getPosixId(errno)));
163: TclList.append(interp, threeEltListObj, TclString
164: .newInstance(msg));
165:
166: interp.setErrorCode(threeEltListObj);
167:
168: if (interp != null) {
169: if (appendPosixMsg) {
170: interp.setResult(errorMsg + ": " + msg);
171: } else {
172: interp.setResult(errorMsg);
173: }
174: }
175: }
176:
177: /*
178: *----------------------------------------------------------------------
179: *
180: * getPosixId --
181: *
182: * Return the string form of "errno".
183: *
184: * Returns:
185: * An error name String.
186: *
187: * Side effects:
188: * None.
189: *
190: *----------------------------------------------------------------------
191: */
192:
193: private static String getPosixId(int errno) // Code of posix error.
194: {
195: switch (errno) {
196: case E2BIG:
197: return "E2BIG";
198: case EACCES:
199: return "EACCES";
200: case EADDRINUSE:
201: return "EADDRINUSE";
202: case EADDRNOTAVAIL:
203: return "EADDRNOTAVAIL";
204: //case EADV: return "EADV";
205: case EAFNOSUPPORT:
206: return "EAFNOSUPPORT";
207: case EAGAIN:
208: return "EAGAIN";
209: //case EALIGN: return "EALIGN";
210: case EALREADY:
211: return "EALREADY";
212: //case EBADE: return "EBADE";
213: case EBADF:
214: return "EBADF";
215: //case EBADFD: return "EBADFD";
216: //case EBADMSG: return "EBADMSG";
217: //case EBADR: return "EBADR";
218: case EBADRPC:
219: return "EBADRPC";
220: //case EBADRQC: return "EBADRQC";
221: //case EBADSLT: return "EBADSLT";
222: //case EBFONT: return "EBFONT";
223: case EBUSY:
224: return "EBUSY";
225: case ECHILD:
226: return "ECHILD";
227: //case ECHRNG: return "ECHRNG";
228: //case ECOMM: return "ECOMM";
229: case ECONNABORTED:
230: return "ECONNABORTED";
231: case ECONNREFUSED:
232: return "ECONNREFUSED";
233: case ECONNRESET:
234: return "ECONNRESET";
235: case EDEADLK:
236: return "EDEADLK";
237: //case EDEADLOCK: return "EDEADLOCK";
238: case EDESTADDRREQ:
239: return "EDESTADDRREQ";
240: //case EDIRTY: return "EDIRTY";
241: case EDOM:
242: return "EDOM";
243: //case EDOTDOT: return "EDOTDOT";
244: case EDQUOT:
245: return "EDQUOT";
246: //case EDUPPKG: return "EDUPPKG";
247: case EEXIST:
248: return "EEXIST";
249: case EFAULT:
250: return "EFAULT";
251: case EFBIG:
252: return "EFBIG";
253: case EHOSTDOWN:
254: return "EHOSTDOWN";
255: case EHOSTUNREACH:
256: return "EHOSTUNREACH";
257: //case EIDRM: return "EIDRM";
258: //case EINIT: return "EINIT";
259: case EINPROGRESS:
260: return "EINPROGRESS";
261: case EINTR:
262: return "EINTR";
263: case EINVAL:
264: return "EINVAL";
265: case EIO:
266: return "EIO";
267: case EISCONN:
268: return "EISCONN";
269: case EISDIR:
270: return "EISDIR";
271: //case EISNAM: return "EISNAM";
272: //case ELBIN: return "ELBIN";
273: //case EL2HLT: return "EL2HLT";
274: //case EL2NSYNC: return "EL2NSYNC";
275: //case EL3HLT: return "EL3HLT";
276: //case EL3RST: return "EL3RST";
277: //case ELIBACC: return "ELIBACC";
278: //case ELIBBAD: return "ELIBBAD";
279: //case ELIBEXEC: return "ELIBEXEC";
280: //case ELIBMAX: return "ELIBMAX";
281: //case ELIBSCN: return "ELIBSCN";
282: //case ELNRNG: return "ELNRNG";
283: case ELOOP:
284: return "ELOOP";
285: case EMLINK:
286: return "EMLINK";
287: case EMSGSIZE:
288: return "EMSGSIZE";
289: //case EMULTIHOP: return "EMULTIHOP";
290: case ENAMETOOLONG:
291: return "ENAMETOOLONG";
292: //case ENAVAIL: return "ENAVAIL";
293: //case ENET: return "ENET";
294: case ENETDOWN:
295: return "ENETDOWN";
296: case ENETRESET:
297: return "ENETRESET";
298: case ENETUNREACH:
299: return "ENETUNREACH";
300: case ENFILE:
301: return "ENFILE";
302: //case ENOANO: return "ENOANO";
303: case ENOBUFS:
304: return "ENOBUFS";
305: //case ENOCSI: return "ENOCSI";
306: //case ENODATA: return "ENODATA";
307: case ENODEV:
308: return "ENODEV";
309: case ENOENT:
310: return "ENOENT";
311: case ENOEXEC:
312: return "ENOEXEC";
313: case ENOLCK:
314: return "ENOLCK";
315: //case ENOLINK: return "ENOLINK";
316: case ENOMEM:
317: return "ENOMEM";
318: //case ENOMSG: return "ENOMSG";
319: //case ENONET: return "ENONET";
320: //case ENOPKG: return "ENOPKG";
321: case ENOPROTOOPT:
322: return "ENOPROTOOPT";
323: case ENOSPC:
324: return "ENOSPC";
325: //case ENOSR: return "ENOSR";
326: //case ENOSTR: return "ENOSTR";
327: //case ENOSYM: return "ENOSYM";
328: case ENOSYS:
329: return "ENOSYS";
330: case ENOTBLK:
331: return "ENOTBLK";
332: case ENOTCONN:
333: return "ENOTCONN";
334: case ENOTDIR:
335: return "ENOTDIR";
336: case ENOTEMPTY:
337: return "ENOTEMPTY";
338: //case ENOTNAM: return "ENOTNAM";
339: case ENOTSOCK:
340: return "ENOTSOCK";
341: //case ENOTSUP: return "ENOTSUP";
342: case ENOTTY:
343: return "ENOTTY";
344: //case ENOTUNIQ: return "ENOTUNIQ";
345: case ENXIO:
346: return "ENXIO";
347: case EOPNOTSUPP:
348: return "EOPNOTSUPP";
349: case EPERM:
350: return "EPERM";
351: case EPFNOSUPPORT:
352: return "EPFNOSUPPORT";
353: case EPIPE:
354: return "EPIPE";
355: case EPROCLIM:
356: return "EPROCLIM";
357: case EPROCUNAVAIL:
358: return "EPROCUNAVAIL";
359: case EPROGMISMATCH:
360: return "EPROGMISMATCH";
361: case EPROGUNAVAIL:
362: return "EPROGUNAVAIL";
363: //case EPROTO: return "EPROTO";
364: case EPROTONOSUPPORT:
365: return "EPROTONOSUPPORT";
366: case EPROTOTYPE:
367: return "EPROTOTYPE";
368: case ERANGE:
369: return "ERANGE";
370: //case EREFUSED: return "EREFUSED";
371: //case EREMCHG: return "EREMCHG";
372: //case EREMDEV: return "EREMDEV";
373: case EREMOTE:
374: return "EREMOTE";
375: //case EREMOTEIO: return "EREMOTEIO";
376: //case EREMOTERELEASE: return "EREMOTERELEASE";
377: case EROFS:
378: return "EROFS";
379: case ERPCMISMATCH:
380: return "ERPCMISMATCH";
381: //case ERREMOTE: return "ERREMOTE";
382: case ESHUTDOWN:
383: return "ESHUTDOWN";
384: case ESOCKTNOSUPPORT:
385: return "ESOCKTNOSUPPORT";
386: case ESPIPE:
387: return "ESPIPE";
388: case ESRCH:
389: return "ESRCH";
390: //case ESRMNT: return "ESRMNT";
391: case ESTALE:
392: return "ESTALE";
393: //case ESUCCESS: return "ESUCCESS";
394: //case ETIME: return "ETIME";
395: case ETIMEDOUT:
396: return "ETIMEDOUT";
397: case ETOOMANYREFS:
398: return "ETOOMANYREFS";
399: case ETXTBSY:
400: return "ETXTBSY";
401: //case EUCLEAN: return "EUCLEAN";
402: //case EUNATCH: return "EUNATCH";
403: case EUSERS:
404: return "EUSERS";
405: //case EVERSION: return "EVERSION";
406: //case EWOULDBLOCK: return "EWOULDBLOCK";
407: case EXDEV:
408: return "EXDEV";
409: //case EXFULL: return "EXFULL";
410: }
411: return "unknown error";
412: }
413:
414: /*
415: *----------------------------------------------------------------------
416: *
417: * getPosixMsg --
418: *
419: * Return the message string corresponding to "errno".
420: *
421: * Returns:
422: * An error message String.
423: *
424: * Side effects:
425: * None.
426: *
427: *----------------------------------------------------------------------
428: */
429:
430: static String getPosixMsg(int errno) // Code of posix error.
431: {
432: switch (errno) {
433: case E2BIG:
434: return "argument list too long";
435: case EACCES:
436: return "permission denied";
437: case EADDRINUSE:
438: return "address already in use";
439: case EADDRNOTAVAIL:
440: return "can't assign requested address";
441: //case EADV: return "advertise error";
442: case EAFNOSUPPORT:
443: return "address family not supported by protocol family";
444: case EAGAIN:
445: return "resource temporarily unavailable";
446: //case EALIGN: return "EALIGN";
447: case EALREADY:
448: return "operation already in progress";
449: //case EBADE: return "bad exchange descriptor";
450: case EBADF:
451: return "bad file number";
452: //case EBADFD: return "file descriptor in bad state";
453: //case EBADMSG: return "not a data message";
454: //case EBADR: return "bad request descriptor";
455: case EBADRPC:
456: return "RPC structure is bad";
457: //case EBADRQC: return "bad request code";
458: //case EBADSLT: return "invalid slot";
459: //case EBFONT: return "bad font file format";
460: case EBUSY:
461: return "file busy";
462: case ECHILD:
463: return "no children";
464: //case ECHRNG: return "channel number out of range";
465: //case ECOMM: return "communication error on send";
466: case ECONNABORTED:
467: return "software caused connection abort";
468: case ECONNREFUSED:
469: return "connection refused";
470: case ECONNRESET:
471: return "connection reset by peer";
472: case EDEADLK:
473: return "resource deadlock avoided";
474: //case EDEADLOCK: return "resource deadlock avoided";
475: case EDESTADDRREQ:
476: return "destination address required";
477: //case EDIRTY: return "mounting a dirty fs w/o force";
478: case EDOM:
479: return "math argument out of range";
480: //case EDOTDOT: return "cross mount point";
481: case EDQUOT:
482: return "disk quota exceeded";
483: //case EDUPPKG: return "duplicate package name";
484: case EEXIST:
485: return "file already exists";
486: case EFAULT:
487: return "bad address in system call argument";
488: case EFBIG:
489: return "file too large";
490: case EHOSTDOWN:
491: return "host is down";
492: case EHOSTUNREACH:
493: return "host is unreachable";
494: //case EIDRM: return "identifier removed";
495: //case EINIT: return "initialization error";
496: case EINPROGRESS:
497: return "operation now in progress";
498: case EINTR:
499: return "interrupted system call";
500: case EINVAL:
501: return "invalid argument";
502: case EIO:
503: return "I/O error";
504: case EISCONN:
505: return "socket is already connected";
506: case EISDIR:
507: return "illegal operation on a directory";
508: //case EISNAM: return "is a name file";
509: //case ELBIN: return "ELBIN";
510: //case EL2HLT: return "level 2 halted";
511: //case EL2NSYNC: return "level 2 not synchronized";
512: //case EL3HLT: return "level 3 halted";
513: //case EL3RST: return "level 3 reset";
514: //case ELIBACC: return "can not access a needed shared library";
515: //case ELIBBAD: return "accessing a corrupted shared library";
516: //case ELIBEXEC: return "can not exec a shared library directly";
517: //case ELIBMAX: return
518: //"attempting to link in more shared libraries than system limit";
519: //case ELIBSCN: return ".lib section in a.out corrupted";
520: //case ELNRNG: return "link number out of range";
521: case ELOOP:
522: return "too many levels of symbolic links";
523: case EMFILE:
524: return "too many open files";
525: case EMLINK:
526: return "too many links";
527: case EMSGSIZE:
528: return "message too long";
529: //case EMULTIHOP: return "multihop attempted";
530: case ENAMETOOLONG:
531: return "file name too long";
532: //case ENAVAIL: return "not available";
533: //case ENET: return "ENET";
534: case ENETDOWN:
535: return "network is down";
536: case ENETRESET:
537: return "network dropped connection on reset";
538: case ENETUNREACH:
539: return "network is unreachable";
540: case ENFILE:
541: return "file table overflow";
542: //case ENOANO: return "anode table overflow";
543: case ENOBUFS:
544: return "no buffer space available";
545: //case ENOCSI: return "no CSI structure available";
546: //case ENODATA: return "no data available";
547: case ENODEV:
548: return "no such device";
549: case ENOENT:
550: return "no such file or directory";
551: case ENOEXEC:
552: return "exec format error";
553: case ENOLCK:
554: return "no locks available";
555: //case ENOLINK: return "link has be severed";
556: case ENOMEM:
557: return "not enough memory";
558: //case ENOMSG: return "no message of desired type";
559: //case ENONET: return "machine is not on the network";
560: //case ENOPKG: return "package not installed";
561: case ENOPROTOOPT:
562: return "bad proocol option";
563: case ENOSPC:
564: return "no space left on device";
565: //case ENOSR: return "out of stream resources";
566: //case ENOSTR: return "not a stream device";
567: //case ENOSYM: return "unresolved symbol name";
568: case ENOSYS:
569: return "function not implemented";
570: case ENOTBLK:
571: return "block device required";
572: case ENOTCONN:
573: return "socket is not connected";
574: case ENOTDIR:
575: return "not a directory";
576: case ENOTEMPTY:
577: return "directory not empty";
578: //case ENOTNAM: return "not a name file";
579: case ENOTSOCK:
580: return "socket operation on non-socket";
581: //case ENOTSUP: return "operation not supported";
582: case ENOTTY:
583: return "inappropriate device for ioctl";
584: //case ENOTUNIQ: return "name not unique on network";
585: case ENXIO:
586: return "no such device or address";
587: case EOPNOTSUPP:
588: return "operation not supported on socket";
589: case EPERM:
590: return "not owner";
591: case EPFNOSUPPORT:
592: return "protocol family not supported";
593: case EPIPE:
594: return "broken pipe";
595: case EPROCLIM:
596: return "too many processes";
597: case EPROCUNAVAIL:
598: return "bad procedure for program";
599: case EPROGMISMATCH:
600: return "program version wrong";
601: case EPROGUNAVAIL:
602: return "RPC program not available";
603: //case EPROTO: return "protocol error";
604: case EPROTONOSUPPORT:
605: return "protocol not suppored";
606: case EPROTOTYPE:
607: return "protocol wrong type for socket";
608: case ERANGE:
609: return "math result unrepresentable";
610: //case EREFUSED: return "EREFUSED";
611: //case EREMCHG: return "remote address changed";
612: //case EREMDEV: return "remote device";
613: case EREMOTE:
614: return "pathname hit remote file system";
615: //case EREMOTEIO: return "remote i/o error";
616: //case EREMOTERELEASE: return "EREMOTERELEASE";
617: case EROFS:
618: return "read-only file system";
619: case ERPCMISMATCH:
620: return "RPC version is wrong";
621: //case ERREMOTE: return "object is remote";
622: case ESHUTDOWN:
623: return "can't send afer socket shutdown";
624: case ESOCKTNOSUPPORT:
625: return "socket type not supported";
626: case ESPIPE:
627: return "invalid seek";
628: case ESRCH:
629: return "no such process";
630: //case ESRMNT: return "srmount error";
631: case ESTALE:
632: return "stale remote file handle";
633: //case ESUCCESS: return "Error 0";
634: //case ETIME: return "timer expired";
635: case ETIMEDOUT:
636: return "connection timed out";
637: case ETOOMANYREFS:
638: return "too many references: can't splice";
639: case ETXTBSY:
640: return "text file or pseudo-device busy";
641: //case EUCLEAN: return "structure needs cleaning";
642: //case EUNATCH: return "protocol driver not attached";
643: case EUSERS:
644: return "too many users";
645: //case EVERSION: return "version mismatch";
646: //case EWOULDBLOCK: return "operation would block";
647: case EXDEV:
648: return "cross-domain link";
649: //case EXFULL: return "message tables full";
650: default:
651: return "unknown POSIX error";
652: }
653: }
654:
655: } // end TclPosixException class
|