Throw HttpSysException with HttpInitialize status details#66859
Throw HttpSysException with HttpInitialize status details#66859Copilot wants to merge 7 commits into
Conversation
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
| } | ||
|
|
||
| var httpInitializeException = new Win32Exception((int)httpInitializeStatusCode); | ||
| return new PlatformNotSupportedException( |
There was a problem hiding this comment.
Maybe should throw an HttpSysException
|
|
||
| internal static PlatformNotSupportedException CreateHttpInitializeFailureException(uint httpInitializeStatusCode) | ||
| { | ||
| if (httpInitializeStatusCode == ErrorCodes.ERROR_SUCCESS) |
|
@copilot react to feedback |
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
| } | ||
|
|
||
| var httpInitializeException = new HttpSysException((int)httpInitializeStatusCode); | ||
| return new PlatformNotSupportedException( |
There was a problem hiding this comment.
Wonder if this should just throw the HttpSysException? Any reason to keep using PlatformNotSupportedException?
There was a problem hiding this comment.
Updated in 6b01d35: for non-success HttpInitialize status codes, HttpSysListener now throws HttpSysException directly (with status code + HRESULT in the message). The ERROR_SUCCESS branch still falls back to PlatformNotSupportedException since there is no native failure code to surface.
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
| var hResult = CreateHResultFromWin32Error(httpInitializeStatusCode); | ||
| return new HttpSysException( | ||
| (int)httpInitializeStatusCode, | ||
| $"HttpInitialize failed with status code 0x{httpInitializeStatusCode:X8} (HRESULT 0x{hResult:X8})."); |
There was a problem hiding this comment.
Updated in 502f04ff: removed the HRESULT text from the HttpInitialize failure message and updated the related HttpSysListenerTests assertions to only validate the status code and exception type/error code.
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves Http.Sys startup diagnostics by preserving and surfacing the native HttpInitialize return status when HttpApi.Supported is false, so failures provide actionable error information instead of a generic PlatformNotSupportedException.
Changes:
- Added
HttpApi.HttpInitializeStatusCodeto retain theHttpInitializereturn value fromHttpApistatic initialization. - Updated
HttpSysListenerto throw a tailored exception viaCreateHttpInitializeFailureException(...)when Http.Sys initialization is not supported. - Added unit tests validating exception type/contents for both success and non-success status codes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Servers/HttpSys/test/Tests/HttpSysListenerTests.cs | Adds unit tests for the new initialization-failure exception behavior. |
| src/Servers/HttpSys/src/NativeInterop/HttpApi.cs | Persists HttpInitialize status code for later diagnostics. |
| src/Servers/HttpSys/src/HttpSysListener.cs | Throws a diagnostic exception (including status code) when HttpInitialize support is unavailable. |
| public void CreateHttpInitializeFailureException_WithErrorCode_ReturnsHttpSysExceptionWithDetails() | ||
| { | ||
| var errorCode = ErrorCodes.ERROR_ACCESS_DENIED; | ||
| var exception = Assert.IsType<HttpSysException>(HttpSysListener.CreateHttpInitializeFailureException(errorCode)); | ||
|
|
||
| Assert.Contains($"status code 0x{errorCode:X8}", exception.Message); |
| return new HttpSysException( | ||
| (int)httpInitializeStatusCode, | ||
| $"HttpInitialize failed with status code 0x{httpInitializeStatusCode:X8}."); |
Throw HttpSysException with HttpInitialize status details
Surface actionable diagnostics when
HttpInitializefails during Http.Sys startup.Description
HttpSysListenerpreviously threw a barePlatformNotSupportedExceptionwhenHttpApi.Supportedwas false, hiding native failure details.HttpApi.HttpInitializeStatusCodeto persist the nativeHttpInitializereturn value.HttpSysListenerwithCreateHttpInitializeFailureException(...).HttpSysExceptiondirectly (instead of wrapping it).0xXXXXXXXX).PlatformNotSupportedExceptionfallback when status isERROR_SUCCESS(no specific native error to surface).HttpSysExceptionwith status detailsPlatformNotSupportedExceptionwithout inner exceptionCustomer Impact
Http.Sys startup failures now provide immediate root-cause diagnostics with native error semantics (
HttpSysException+ status code), reducing investigation time for unsupported/failed initialization environments.Regression?
[If yes, specify the version the behavior has regressed from]
Risk
Error-path exception enrichment and exception-type refinement only; no request-processing behavior changes.
Verification
Packaging changes reviewed?
When servicing release/2.3