Disable warnings notifications in WSLC (#40751)

Blue committed Jun 8, 2026 at 18:36 UTC 516df00f3e080551a116d83731113c1d61c244d7
3 files changed +7 -5
src/windows/common/ExecutionContext.cpp
+4 -2
@@ -15,14 +15,16 @@ thread_local ExecutionContext* g_currentContext = nullptr;
15 static bool g_enabled = false;
16 bool g_runningInService = false;
17 bool g_useComErrors = false;
18 +bool g_enableNotifications = false;
19 static HANDLE g_eventLog = nullptr;
20
20 -void wsl::windows::common::EnableContextualizedErrors(bool service, bool useComErrors)
21 +void wsl::windows::common::EnableContextualizedErrors(bool service, bool useComErrors, bool enableNotifications)
22 {
23 WI_ASSERT(!g_enabled);
24 g_enabled = true;
25 g_runningInService = service;
26 g_useComErrors = useComErrors;
27 + g_enableNotifications = enableNotifications;
28 }
29
30 ExecutionContext::ExecutionContext(Context context, FILE* warningsFile) noexcept :
@@ -169,7 +171,7 @@ void ExecutionContext::EmitUserWarning(const std::wstring& warning, const std::s
171 return;
172 }
173
172 - if (!CollectUserWarning(std::format(L"wsl: {}\n", warning)))
174 + if (!CollectUserWarning(std::format(L"wsl: {}\n", warning)) && g_enableNotifications)
175 {
176 static std::atomic<bool> displayed = false;
177 if (!displayed.exchange(true))
src/windows/common/ExecutionContext.h
+2 -2
@@ -217,11 +217,11 @@ public:
217 bool CanCollectUserErrorMessage() override;
218 };
219
220 -void EnableContextualizedErrors(bool service, bool useComErrors = false);
220 +void EnableContextualizedErrors(bool service, bool useComErrors = false, bool enableNotifications = false);
221
222 void SetErrorMessage(std::wstring&& message, const std::source_location& source = std::source_location::current());
223 void SetErrorMessage(std::string&& message, const std::source_location& source = std::source_location::current());
224
225 void SetEventLog(HANDLE eventLog);
226
227 -} // namespace wsl::windows::common
\ No newline at end of file
227 +} // namespace wsl::windows::common
src/windows/service/exe/ServiceMain.cpp
+1 -1
@@ -164,7 +164,7 @@ try
164 ConfigureCrt();
165
166 // Enable contextualized errors
167 - wsl::windows::common::EnableContextualizedErrors(true);
167 + wsl::windows::common::EnableContextualizedErrors(true, false, true);
168
169 // Initialize telemetry.
170 WslTraceLoggingInitialize(WslServiceTelemetryProvider, !wsl::shared::OfficialBuild);