Skip to content

Commit cb8bc9a

Browse files
benhillisBen Hillis
andauthored
cleanup: hcs logging improvements (#13942)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent a4f1f7a commit cb8bc9a

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/windows/common/hcs.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ wsl::windows::common::hcs::unique_hcs_system wsl::windows::common::hcs::CreateCo
8686

8787
wil::unique_cotaskmem_string resultDocument;
8888
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+
}
9595

9696
return system;
9797
}
@@ -137,8 +137,7 @@ GUID wsl::windows::common::hcs::GetRuntimeId(_In_ HCS_SYSTEM ComputeSystem)
137137

138138
wil::unique_cotaskmem_string resultDocument;
139139
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());
142141

143142
const auto properties = wsl::shared::FromJson<Properties>(resultDocument.get());
144143
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
193192

194193
wil::unique_cotaskmem_string resultDocument;
195194
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());
201196
}
202197

203198
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
241236

242237
wil::unique_cotaskmem_string resultDocument;
243238
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);
249240
}
250241

251242
void wsl::windows::common::hcs::TerminateComputeSystem(_In_ HCS_SYSTEM ComputeSystem)
@@ -257,8 +248,7 @@ void wsl::windows::common::hcs::TerminateComputeSystem(_In_ HCS_SYSTEM ComputeSy
257248

258249
wil::unique_cotaskmem_string resultDocument;
259250
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());
262252
}
263253

264254
wsl::windows::common::hcs::unique_hcn_service_callback wsl::windows::common::hcs::RegisterServiceCallback(

0 commit comments

Comments
 (0)