Skip to content

Commit ee37178

Browse files
committed
improve RpcClient error reporting in call()
1 parent f2a287d commit ee37178

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

windows/rpc/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ def _get_request_type(self, response):
205205
"raise if request_type == RESPONSE_TYPE_FAIL"
206206
request_type = struct.unpack("<I", response.data[:4])[0]
207207
if request_type == gdef.RPC_RESPONSE_TYPE_FAIL:
208-
error_code = struct.unpack("<5I", response.data)[2]
209-
raise ValueError("RPC Response error {0} ({1!r})".format(error_code, KNOWN_RPC_ERROR_CODE.get(error_code, error_code)))
208+
effective_error_code = error_code = struct.unpack("<5I", response.data)[2]
209+
# https://learn.microsoft.com/en-us/windows/win32/com/structure-of-com-error-codes
210+
if gdef.HRESULT_FACILITY(error_code) == gdef.FACILITY_WIN32:
211+
effective_error_code = effective_error_code & 0xffff
212+
raise ValueError("RPC Response error {0:#x} ({1!r})".format(error_code, KNOWN_RPC_ERROR_CODE[effective_error_code]))
210213
return request_type
211214

212215
def _get_response_effective_data(self, response):

0 commit comments

Comments
 (0)