Skip to content

WinHttp Transport logging (and exception strings) have dangling periods making it harder to read due to new line in errorMsg from winhttp #5154

@ahsonkhan

Description

@ahsonkhan

errorString.get(); returns something like "Foo\n" and hence adding the trailing period (and subsequent DWORD error to string) ends up in a new line.

From

std::string GetErrorMessage(DWORD error)
{
std::string errorMessage = " Error Code: " + std::to_string(error);
char* errorMsg = nullptr;
if (FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
GetModuleHandle("winhttp.dll"),
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&errorMsg),
0,
nullptr)
!= 0)
{
// Use a unique_ptr to manage the lifetime of errorMsg.
std::unique_ptr<char, decltype(&LocalFree)> errorString(errorMsg, &LocalFree);
errorMsg = nullptr;
errorMessage += ": ";
errorMessage += errorString.get();
}
errorMessage += '.';
return errorMessage;
}

The logs, which also end up emitting the exception message (in the transport layer) end up like this:

[2023-11-10T23:26:43.1726294Z T: 38480] INFO  : Status operation: 2097152(WINHTTP_CALLBACK_STATUS_REQUEST_ERROR )
[2023-11-10T23:26:43.1733686Z T: 38480] ERROR : Request error.  Error Code: 12002: The operation timed out
. 1
[2023-11-10T23:26:43.1738532Z T: 38480] DEBUG : WinHttpRequest::~WinHttpRequest. Closing handle synchronously.

image

cc @LarryOsterman

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions