Tcl Source Code

View Ticket
Login
2022-04-05
06:31 Closed ticket [800716ffff]: publicize TclWinConvertError and TclWinConvertWSAError plus 9 other changes artifact: e395a0dd4d user: jan.nijtmans
2003-09-10
08:13 Ticket [800716ffff]: 4 changes artifact: 0a8d85cd2c user: davygrvy
07:18 Ticket [800716ffff]: 4 changes artifact: 11f5b82df8 user: davygrvy
07:07 Add attachment patch.zip to ticket [800716ffff] artifact: 759343a11d user: davygrvy
07:07 Ticket [800716ffff] publicize TclWinConvertError and TclWinConvertWSAError status still Open with 4 other changes artifact: 838e13c824 user: davygrvy
07:05 Ticket [800716ffff]: 4 changes artifact: 8cf218dead user: davygrvy
2003-09-05
21:58 Ticket [800716ffff]: 4 changes artifact: 8e59eb5a4c user: dgp
18:51 Ticket [800716ffff]: 4 changes artifact: b95a8ed2d0 user: davygrvy
17:35 Ticket [800716ffff]: 4 changes artifact: 2a69756dcc user: davygrvy
04:38 Ticket [800716ffff]: 4 changes artifact: 12b1ba2333 user: davygrvy
04:38 Add attachment patch.txt to ticket [800716ffff] artifact: 4a274eef40 user: davygrvy
2003-09-04
21:37 New ticket [800716ffff] publicize TclWinConvertError and TclWinConvertWSAError. artifact: 2aca1d5917 user: davygrvy

Ticket UUID: 800716
Title: publicize TclWinConvertError and TclWinConvertWSAError
Type: Patch Version: None
Submitter: davygrvy Created on: 2003-09-04 21:37:59
Subsystem: 52. Portability Support Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2022-04-05 06:31:39
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2022-04-05 06:31:39
Description:
TclWinConvertError and TclWinConvertWSAError are 
private internal functions.  They could be very useful to 
extension authors.  I see a need for it.  Let's make them 
public.

Also, TclWinConvertWSAError doesn't map to all WSAE* 
error codes.  Included are mappings to all of them.  
Unfortunetly, all the added can only return EINVAL until 
the posix codes they translate into get more meaningful 
to windows.  Effectively, the behavior is still unchanged.

Example:

WSA_QOS_POLICY_FAILURE,  'rejected for administrative 
reasons - bad credentials'
WSAEPROVIDERFAILEDINIT, 'The requested service 
provider could not be loaded or initialized'

What posix codes do those get?  Some detective work 
needs to be done with these.  I really don't have a clue.

The main reason I want to enlargen the mappings is to 
include WSAHOST_NOT_FOUND.  I hate that the 
[socket] command can only return 'invalid argument' 
instead of 'authoritative host not found' or 'try again', 
or ....

Should this really be a TIP?
User Comments: jan.nijtmans added on 2022-04-05 06:31:39:

Done: https://core.tcl-lang.org/tips/doc/trunk/tip/598.md


davygrvy added on 2003-09-10 08:13:24:
Logged In: YES 
user_id=7549

Here's some code that shows how an extension could make 
use of this feature:

CONST char *
ExpWinExpError TCL_VARARGS_DEF(Tcl_Interp *, arg1)
{
    CONST char *id, *msg;
    va_list argList;
    Tcl_Interp *interp;
    DWORD err = GetLastError();

    interp = TCL_VARARGS_START(Tcl_Interp *, arg1, argList);

    /*
     * If the "customer" bit is set, this error is ours. else 
forward
     * it to the system.
     */

    if (errorCode & (0x1 << 29)) {
id = ExpWinExpErrId(err);
msg = ExpWinExpErrMsgVA(err, argList);
Tcl_SetErrorCode(interp, "EXPECT", id, msg, 0L);
    } else {
id = Tcl_Win32ErrId(err);
msg = Tcl_Win32ErrMsgVA(err, argList);
Tcl_SetErrorCode(interp, "WIN32", id, msg, 0L);
    }
    va_end(argList);
    return msg;
}

davygrvy added on 2003-09-10 07:18:50:
Logged In: YES 
user_id=7549

Code could be added so that if Tcl(_)WinConvertError can't 
make the translation, the native message could be used 
instead.

But Tcl is supposed to the great equilizer, and this new 
concept might be foriegn as it attemps to break from 'least 
common denominator' hole and might not be helpful for the 
places that are to provide a generic interface.

In places where the native message is desirable, the ability to 
get it, is now easy.

davygrvy added on 2003-09-10 07:07:42:

File Added - 61125: patch.zip

davygrvy added on 2003-09-10 07:05:07:
Logged In: YES 
user_id=7549

Here's another patch that adds Tcl_Win32Error(), 
Tcl_Win32ErrId(), Tcl_Win32ErrMsg(), and Tcl_Win32ErrMsgVA
().

The concept of setting errno and returning from a function is 
usually then displayed to the user with Tcl_PosixError() in a 
generic layer for setting $errorCode.  Tcl_Win32Error() is 
exactly analogous to that, except that it gets the error code 
from GetLastError() for the exact windows error.

I would use this from an extension!  See the shift?  Instead of 
returning from a function with errno set, give the function the 
interp and let it set $errorCode itself.  This concept is working 
well in a project I'm doing.  NOTHING is getting lost in a 
translation as there aren't any to be made!

Tcl_Win32ErrId() is 100% complete and match the october 
2002 release of the platform SDK.  Error messages are asked 
for from the system with FormatMessage and could support 
localization...

win/tclWinError.c builds with stock VC5, VC6, and with the 
platform SDK headers, too.

my wrists are sore.. where's an ice pack in this house?

dgp added on 2003-09-05 21:58:23:
Logged In: YES 
user_id=80530


Localized error messages are
 still a good idea, just one that needs
to wait for a more thorough use of
::errorCode for script processing.
jenglish and kbk both have ideas
on this, but over a fairly extended
time frame.

davygrvy added on 2003-09-05 18:51:57:
Logged In: YES 
user_id=7549

Please ignore that last post.  That would break ALL scripts 
that did matching on error messages ;)

davygrvy added on 2003-09-05 17:35:46:
Logged In: YES 
user_id=7549

It would be nice also, if Tcl_ErrnoMsg() returned localized 
strings.

davygrvy added on 2003-09-05 04:38:00:

File Added - 60637: patch.txt

Attachments: