microsoft / wil

Windows Implementation Library
MIT License
2.57k stars 234 forks source link

Adding macro RETURN_IF_FAILED_SUPPRESS_TELEMETRY_IF_EXPECTED #428

Closed araujoarthur0 closed 7 months ago

araujoarthur0 commented 7 months ago

Closes #425.

For the result macros, when one sets a telemetry fallback provider with SetResultTelemetryFallback() and a logging callback with SetResultLoggingCallback(), we always log and send telemetry for HRESULT failures in the RETURN_ macros. The _EXPECTED macros allows one to skip the reporting for some expected HRESULTs, but that suppresses both logging and telemetry. There was no alternative if one wanted to always log failures but just suppress telemetry in case the HRESULT was expected.

The new macro RETURN_IF_FAILED_SUPPRESS_TELEMETRY_IF_EXPECTED returns an HRESULT if it failed, always logging those failures, but sends a suppressed telemetry callback if the HRESULT matches one of the expected HRESULT values. The way this is done is leveraging the existing enum FailureFlags::SuppressTelemetry. This enum makes the telemetry callback be called with alreadyReported as true.

There is a new parameter FailureFlags to the internal ReturnHr methods in result_macros.h.

New tests were added to check the feature behavior.

araujoarthur0 commented 7 months ago

@microsoft-github-policy-service agree