cleanup: hcs logging improvements (#13942)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Ben Hillis committed
Dec 19, 2025 at 13:23 UTC
cb8bc9af677fb788a855a07e2f9949f952795106
1 file changed
+10
-20
src/windows/common/hcs.cpp
+10
-20
@@ -86,12 +86,12 @@ wsl::windows::common::hcs::unique_hcs_system wsl::windows::common::hcs::CreateCo
86
87
wil::unique_cotaskmem_string resultDocument;
88
const auto result = ::HcsWaitForOperationResult(operation.get(), INFINITE, &resultDocument);
89
- THROW_IF_FAILED_MSG(
90
- result,
91
- "HcsWaitForOperationResult for HcsCreateComputeSystem failed (%ls %ls - error string: %ls)",
92
- Id,
93
- Configuration,
94
- resultDocument.get());
89
+ if (FAILED(result))
90
+ {
91
+ // N.B. Logging is split into two calls because the configuration and error strings can be quite long.
92
+ LOG_HR_MSG(result, "HcsCreateComputeSystem(%ls, %ls)", Id, Configuration);
93
+ THROW_HR_MSG(result, "HcsCreateComputeSystem failed (error string: %ls)", resultDocument.get());
94
+ }
95
96
return system;
97
}
@@ -137,8 +137,7 @@ GUID wsl::windows::common::hcs::GetRuntimeId(_In_ HCS_SYSTEM ComputeSystem)
137
138
wil::unique_cotaskmem_string resultDocument;
139
const auto result = ::HcsWaitForOperationResult(operation.get(), INFINITE, &resultDocument);
140
- THROW_IF_FAILED_MSG(
141
- result, "HcsWaitForOperationResult for HcsGetComputeSystemProperties failed (error string: %ls)", resultDocument.get());
140
+ THROW_IF_FAILED_MSG(result, "HcsGetComputeSystemProperties failed (error string: %ls)", resultDocument.get());
141
142
const auto properties = wsl::shared::FromJson<Properties>(resultDocument.get());
143
THROW_HR_IF(HCS_E_SYSTEM_NOT_FOUND, (properties.SystemType != SystemType::VirtualMachine));
@@ -193,11 +192,7 @@ void wsl::windows::common::hcs::ModifyComputeSystem(_In_ HCS_SYSTEM ComputeSyste
192
193
wil::unique_cotaskmem_string resultDocument;
194
const auto result = ::HcsWaitForOperationResult(operation.get(), INFINITE, &resultDocument);
196
- THROW_IF_FAILED_MSG(
197
- result,
198
- "HcsWaitForOperationResult for HcsModifyComputeSystem failed (%ls - error string: %ls)",
199
- Configuration,
200
- resultDocument.get());
195
+ THROW_IF_FAILED_MSG(result, "HcsModifyComputeSystem failed (%ls - error string: %ls)", Configuration, resultDocument.get());
196
}
197
198
wsl::windows::common::hcs::unique_hcs_system wsl::windows::common::hcs::OpenComputeSystem(_In_ PCWSTR Id, _In_ DWORD RequestedAccess)
@@ -241,11 +236,7 @@ void wsl::windows::common::hcs::StartComputeSystem(_In_ HCS_SYSTEM ComputeSystem
236
237
wil::unique_cotaskmem_string resultDocument;
238
const auto result = ::HcsWaitForOperationResult(operation.get(), INFINITE, &resultDocument);
244
- THROW_IF_FAILED_MSG(
245
- result,
246
- "HcsWaitForOperationResult for HcsStartComputeSystem failed (error string: %ls, configuration: %ls)",
247
- resultDocument.get(),
248
- Configuration);
239
+ THROW_IF_FAILED_MSG(result, "HcsStartComputeSystem failed (error string: %ls, configuration: %ls)", resultDocument.get(), Configuration);
240
}
241
242
void wsl::windows::common::hcs::TerminateComputeSystem(_In_ HCS_SYSTEM ComputeSystem)
@@ -257,8 +248,7 @@ void wsl::windows::common::hcs::TerminateComputeSystem(_In_ HCS_SYSTEM ComputeSy
248
249
wil::unique_cotaskmem_string resultDocument;
250
const auto result = ::HcsWaitForOperationResult(operation.get(), INFINITE, &resultDocument);
260
- THROW_IF_FAILED_MSG(
261
- result, "HcsWaitForOperationResult for HcsTerminateComputeSystem failed (error string: %ls)", resultDocument.get());
251
+ THROW_IF_FAILED_MSG(result, "HcsTerminateComputeSystem failed (error string: %ls)", resultDocument.get());
252
}
253
254
wsl::windows::common::hcs::unique_hcn_service_callback wsl::windows::common::hcs::RegisterServiceCallback(