Skip to content

CDRIVER-6019 Improve error messages from Windows APIs #2020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented May 21, 2025

Summary

Improve error messages from Windows APIs

Patch build: https://spruce.mongodb.com/version/682dfd72aeaf7a000773acc6

Background

This PR intends to consistently use FormatMessage to get an error message from a Windows error code.

Using the return value from InitializeSecurityContext improves an error message observed when investigating TLS handshake failure as part of CDRIVER-6000:

Before:

Failed to initialize security context: (0x00000001) Incorrect function.

After:

Failed to initialize security context: (0x80090331) The client and server cannot communicate, because they do not possess a common algorithm.

The Windows error types used in libmongoc (SECURITY_STATUS, DNS_STATUS, and return of GetLastError()) all appear accepted in FormatMessage (expects a DWORD). A test is added with a sample of error codes to check the messages.

FormatMessageA is used rather than FormatMessage/FormatMessageW to ensure the resulting error message consists of single-byte characters. The C driver does not test (and appears broken) when building with Unicode encoding on Windows: CDRIVER-6015.

kevinAlbs and others added 4 commits May 21, 2025 15:58
Improves observed "Incorrect function" error with a more informative "The client and server cannot communicate, because they do not possess a common algorithm."
For consistency between Windows / non-Windows
@kevinAlbs kevinAlbs requested a review from a team as a code owner May 21, 2025 20:03
@kevinAlbs kevinAlbs requested a review from vector-of-bool May 21, 2025 20:03
@kevinAlbs kevinAlbs changed the title CDRIVER-4269 Improve error messages from Windows APIs CDRIVER-6019 Improve error messages from Windows APIs May 21, 2025
@kevinAlbs kevinAlbs requested review from mdb-ad and removed request for vector-of-bool May 23, 2025 12:29
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.

1 participant