Skip to content

Commit

Permalink
Unwrap FACILITY_WIN32 HRESULT errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Jan 13, 2025
1 parent 6de1e81 commit ca5e076
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Src/IronPython.Modules/nt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,10 @@ private static string GetWin32ErrorMessage(int errorCode) {

[SupportedOSPlatform("windows")]
internal static Exception GetWin32Error(int winerror, string? filename = null, string? filename2 = null) {
// Unwrap FACILITY_WIN32 HRESULT errors
if ((winerror & 0xFFFF0000) == 0x80070000) {
winerror &= 0x0000FFFF;
}
var msg = GetWin32ErrorMessage(winerror);
return PythonOps.OSError(0, msg, filename, winerror, filename2);
}
Expand Down
7 changes: 6 additions & 1 deletion Src/IronPython/Runtime/Exceptions/PythonExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public partial class _OSError {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
if (args.Length >= 4 && args[3] is int winerror) {
errno = WinErrorToErrno(winerror);
}
}
}
cls = ErrorEnumToPythonType(ErrnoToErrorEnum(errno));
}
Expand Down Expand Up @@ -439,6 +439,11 @@ internal static class Errno {

// See also errmap.h in CPython
internal static int WinErrorToErrno(int winerror) {
// Unwrap FACILITY_WIN32 HRESULT errors
if ((winerror & 0xFFFF0000) == 0x80070000) {
winerror &= 0x0000FFFF;
}

int errno = winerror;
if (winerror < WSABASEERR) {
switch (winerror) {
Expand Down

0 comments on commit ca5e076

Please sign in to comment.