Skip to content

Improve exception messages when Windows fails to load an extension module#1467

Merged
BCSharp merged 1 commit intoIronLanguages:masterfrom
BCSharp:loaddll_error
May 23, 2022
Merged

Improve exception messages when Windows fails to load an extension module#1467
BCSharp merged 1 commit intoIronLanguages:masterfrom
BCSharp:loaddll_error

Conversation

@BCSharp
Copy link
Copy Markdown
Member

@BCSharp BCSharp commented May 22, 2022

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.

Copy link
Copy Markdown
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How'd you pick these error codes for formatting?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BCSharp
Copy link
Copy Markdown
Member Author

BCSharp commented May 23, 2022

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).

I saw that too. ctypes deserves a thorough review and possibly localized redesign. This is not going to happen for me before the summer recess, I'm now just picking up some loose ends that I've noticed.

@BCSharp BCSharp merged commit 9162b30 into IronLanguages:master May 23, 2022
@BCSharp BCSharp deleted the loaddll_error branch May 23, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants