Improve exception messages when Windows fails to load an extension module#1467
Improve exception messages when Windows fails to load an extension module#1467BCSharp merged 1 commit intoIronLanguages:masterfrom
Conversation
slozier
left a comment
There was a problem hiding this comment.
Looks good to me.
Seems like we've got a bunch of versions of the win32 exception handling code. Might be interesting to have something available in the core at some point (like PythonNT.GetLastWin32Error).
| private static string FormatError(int errorCode, string? fileName) { | ||
| string msg = FormatError(errorCode); | ||
| // error codes: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes | ||
| if (errorCode is not (< 0 or >= 8200 or 34 or 106 or 317 or 718)) { |
There was a problem hiding this comment.
How'd you pick these error codes for formatting?
There was a problem hiding this comment.
The link in the comment shows all defined error codes and their messages, grouped by ranges. I searched each range for % to see what variable fields are being used. Luckily, % placeholders are not often used. If a filename is used, it is always on %1 with the four exceptions listed. Above code 8200, filename is not used at all and %1 means something else.
I saw that too. |
Probably I would not have noticed it otherwise but it is explicitly listed in "Whats New In Python 3.0". I have traced the change in CPython regarding this announcement to just two commits: d6179e12 (code) and bccd63c3 (NEWS entry).
The update in this PR reflects the change in IronPython. The old error message in IronPython was generic but contained the file name. The CPython message is specific about the cause of the failure but contains %1 instead of the file name. I remember encountering both in the past and being puzzled in both cases. So this update combines the specific error code/message with the file name (library path) used.