This is not necessarily the current version of this TIP.
| TIP: | 281 |
| Title: | Improvements in System Error Handling |
| Version: | $Revision: 1.1 $ |
| Author: | David Gravereaux <davygrvy at pobox dot com> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Sunday, 08 October 2006 |
| Keywords: | POSIX, channel driver, errorCode |
This TIP describes the need for better error codes and message handling of system errors to be returned to scripts.
The current method for handling of system errors is done via the Tcl_PosixError() API call. Its job is to grab the value of errno and format it for display to a script within the $errorCode special variable. Unfortunately, not all such system errors are left in errno and on Windows, not all information can be translated effectively to a POSIX error code without loss of valuable information to the user.
On UNIX, gethostbyname() for example, leaves its errors in h_errno [1]. If we look at our use of gethostbyname() in unix/tclUnixChan.c for the CreateSocketAddress() function, you'll see we are setting errno to a wrong code rather than retrieving the proper error information defined in netdb.h.
An example of the current mistranslation would be:
% socket foo.example.com 1234
couldn't open socket: host is unreachable
% set errorCode
POSIX EHOSTUNREACH {host is unreachable}
And on Windows:
% socket foo.example.com 1234
couldn't open socket: invalid argument
% set errorCode
POSIX EINVAL {invalid argument}
Notice that the two are different as well as wrong. What I would like to see is the following (on all platforms):
% socket foo.example.com 1234
couldn't open socket: No such host is known
% set errorCode
NETDB HOST_NOT_FOUND {No such host is known}
If we could specify a place from where the error could be retrieved along with the formatting function for that type, Tcl's error information to the user would be improved. A signature and name of the top-level function could be:
CONST char *Tcl_SysError(Tcl_Interp *interp);
Similar to Tcl_PosixError(), but instead of just assuming the location is contained in errno, follow a thread specific variable and call the formatter for that type.
A reference implementation is not done at this time.
This document is in the public domain.
This is not necessarily the current version of this TIP.