terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Corrupted last error after deprecated/unsupported API calls

Open alabuzhev opened this issue 3 years ago • 0 comments

Windows Terminal version

No response

Windows build number

10.0.19044.2006

Other Software

No response

Steps to reproduce

Basically the problem is nicely described in this SO answer.

https://github.com/microsoft/terminal/blob/3c78e01ab5a025290b8953a6dc0f2695c76c223e/src/server/ApiDispatchersInternal.cpp#L22 ServerDeprecatedApi uses E_NOTIMPL (0x80004001), which on its way to the caller suffers several transformations and becomes 0x00004001, which is not a valid Windows error code.

It is quite unfortunate, given that the whole idea is to make it clear to the caller that the call is deprecated/not implemented.

Perhaps the function could use a different code that won't get fubared beyond recognition? Given that it is passed to RtlNtStatusToDosError on its way, it probably should be NTSTATUS in the first place, either just raw STATUS_NOT_IMPLEMENTED or packed into HRESULT as HRESULT_FROM_NT(STATUS_NOT_IMPLEMENTED).

Expected Behavior

After an unsupported call:

  • GetLastError() should return a sensible value, e.g. ERROR_INVALID_FUNCTION or ERROR_CALL_NOT_IMPLEMENTED
  • (optionally) RtlGetLastNtStatus() should return a sensible value, e.g. STATUS_NOT_IMPLEMENTED

Actual Behavior

  • GetLastError() returns 0x0004001, which is an invalid error code.
  • RtlGetLastNtStatus() returns 0xC0074001, which is the same invalid win32 error code with STATUS_SEVERITY_ERROR and FACILITY_NTWIN32 bits.

alabuzhev avatar Dec 02 '22 03:12 alabuzhev