Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,9 @@ This prompt will time out in 60 seconds.</value>
</data>
<data name="MessageErrorCode" xml:space="preserve">
<value>{}
Error code: {}</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
Error code: {}
If this error was unexpected, please consider searching for existing issues or filing a new issue at https://github.com/microsoft/WSL/issues.</value>
Comment thread
craigloewen-msft marked this conversation as resolved.
Comment thread
chemwolf6922 marked this conversation as resolved.
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated{Locked="https://github.com/microsoft/WSL/issues"}</comment>
</data>
<data name="MessageInvalidJson" xml:space="preserve">
<value>Invalid JSON document. Parse error: {}</value>
Expand Down
10 changes: 10 additions & 0 deletions test/windows/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3149,3 +3149,13 @@ void ValidateCOMErrorMessageContains(const std::wstring& ExpectedSubstring)
VERIFY_FAIL();
}
}

std::wstring FormatErrorMessage(std::wstring_view message, std::wstring_view errorCode)
{
return std::format(
L"{}\r\nError code: {}\r\n"
L"If this error was unexpected, please consider searching for existing issues or filing a new issue at "
L"https://github.com/microsoft/WSL/issues.\r\n",
message,
errorCode);
}
2 changes: 2 additions & 0 deletions test/windows/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,3 +723,5 @@ void WriteSocket(SOCKET Socket, const void* data, size_t size);
void ValidateCOMErrorMessage(const std::optional<std::wstring>& Expected, const std::source_location& Source = std::source_location::current());

void ValidateCOMErrorMessageContains(const std::wstring& ExpectedSubstring);

std::wstring FormatErrorMessage(std::wstring_view message, std::wstring_view errorCode);
8 changes: 4 additions & 4 deletions test/windows/InstallerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,10 @@ class InstallerTests
// Validate that calling wsl.exe triggers the install.
auto [output, warnings] = LxsstuLaunchWslAndCaptureOutput(L"echo ok", -1, nulDevice.get());
VERIFY_ARE_EQUAL(
L"\r\nAnother application has exclusive access to the file 'C:\\Program Files\\WSL\\wsl.exe'. Please shut down all "
L"other applications, then click Retry.\r\n"
L"Update failed (exit code: 1603).\r\n"
L"Error code: Wsl/CallMsi/Install/ERROR_INSTALL_FAILURE\r\n",
FormatErrorMessage(
L"\r\nAnother application has exclusive access to the file 'C:\\Program Files\\WSL\\wsl.exe'. Please shut "
L"down all other applications, then click Retry.\r\nUpdate failed (exit code: 1603).",
L"Wsl/CallMsi/Install/ERROR_INSTALL_FAILURE"),
output);
}

Expand Down
5 changes: 3 additions & 2 deletions test/windows/MountTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ class MountTests
const auto [output, error] = LxsstuLaunchWslAndCaptureOutput(mountCommand, -1);
VERIFY_ARE_EQUAL(
output,
L"The mount name cannot be empty, '.', '..', or contain '/'. Please retry with a valid mount name.\r\n"
L"Error code: Wsl/Service/MountDisk/WSL_E_VM_MODE_INVALID_MOUNT_NAME\r\n",
FormatErrorMessage(
L"The mount name cannot be empty, '.', '..', or contain '/'. Please retry with a valid mount name.",
L"Wsl/Service/MountDisk/WSL_E_VM_MODE_INVALID_MOUNT_NAME"),
name);
VERIFY_ARE_EQUAL(error, L"", name);
}
Expand Down
57 changes: 31 additions & 26 deletions test/windows/PluginTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PluginTests
RestartWslService();
}

static void StartWsl(int expectedExitCode, LPCWSTR ExpectedOutput = nullptr)
static void StartWsl(int expectedExitCode, const std::wstring& expectedOutput = {})
{
auto [output, error] = LxsstuLaunchWslAndCaptureOutput(L"echo -n OK", expectedExitCode);
if (expectedExitCode == 0)
Expand All @@ -118,7 +118,7 @@ class PluginTests
}
else
{
VERIFY_ARE_EQUAL(output, ExpectedOutput);
VERIFY_ARE_EQUAL(output, expectedOutput);
}
}

Expand Down Expand Up @@ -299,8 +299,9 @@ class PluginTests
ConfigurePlugin(PluginTestType::Success);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_ACCESSDENIED\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_ACCESSDENIED"));

ValidateLogFile(ExpectedOutput);
}
Expand Down Expand Up @@ -374,8 +375,9 @@ class PluginTests
ConfigurePlugin(PluginTestType::PluginRequiresUpdate);
StartWsl(
-1,
L"The plugin 'TestPlugin' requires a newer version of WSL. Please run: wsl.exe --update\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/WSL_E_PLUGIN_REQUIRES_UPDATE\r\n");
FormatErrorMessage(
L"The plugin 'TestPlugin' requires a newer version of WSL. Please run: wsl.exe --update",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/WSL_E_PLUGIN_REQUIRES_UPDATE"));

ValidateLogFile(ExpectedOutput);
}
Expand Down Expand Up @@ -413,8 +415,8 @@ class PluginTests
ConfigurePlugin(PluginTestType::FailToLoad);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'", L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED"));
ValidateLogFile(ExpectedOutput);
}

Expand All @@ -440,8 +442,8 @@ class PluginTests
ConfigurePlugin(PluginTestType::FailToStartVm);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'", L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED"));
ValidateLogFile(ExpectedOutput);
}

Expand All @@ -460,13 +462,15 @@ class PluginTests

StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'Plugin error message'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'Plugin error message'",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED"));

StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'Plugin error message'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'Plugin error message'",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_UNEXPECTED"));

ValidateLogFile(ExpectedOutput);
}
Expand Down Expand Up @@ -495,12 +499,11 @@ class PluginTests
OnDistroStarted: E_UNEXPECTED
VM Stopping)";

constexpr auto ExpectedError =
L"A fatal error was returned by plugin 'TestPlugin'\r\nError code: "
L"Wsl/Service/CreateInstance/Plugin/E_UNEXPECTED\r\n";

ConfigurePlugin(PluginTestType::FailToStartDistro);
StartWsl(-1, ExpectedError);
StartWsl(
-1,
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'", L"Wsl/Service/CreateInstance/Plugin/E_UNEXPECTED"));
ValidateLogFile(ExpectedOutput);
}

Expand Down Expand Up @@ -530,8 +533,9 @@ class PluginTests
ConfigurePlugin(PluginTestType::ErrorMessageStartVm);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'StartVm plugin error message'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_FAIL\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'StartVm plugin error message'",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/E_FAIL"));

ValidateLogFile(ExpectedOutput);
}
Expand All @@ -548,9 +552,9 @@ class PluginTests
ConfigurePlugin(PluginTestType::ErrorMessageStartDistro);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'StartDistro plugin error message'\r\nError "
L"code: "
L"Wsl/Service/CreateInstance/Plugin/E_FAIL\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'. Error message: 'StartDistro plugin error message'",
L"Wsl/Service/CreateInstance/Plugin/E_FAIL"));

ValidateLogFile(ExpectedOutput);
}
Expand Down Expand Up @@ -1006,7 +1010,8 @@ class PluginTests
ConfigurePlugin(PluginTestType::ErrorMessageStartDistro);
StartWsl(
-1,
L"A fatal error was returned by plugin 'TestPlugin'\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/Plugin/TRUST_E_NOSIGNATURE\r\n");
FormatErrorMessage(
L"A fatal error was returned by plugin 'TestPlugin'",
L"Wsl/Service/CreateInstance/CreateVm/Plugin/TRUST_E_NOSIGNATURE"));
}
};
42 changes: 23 additions & 19 deletions test/windows/PolicyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ class PolicyTest
auto revert = SetPolicy(c_allowDiskMount, 1);
ValidateOutput(
L"--mount DoesNotExist",
L"Failed to attach disk 'DoesNotExist' to WSL2: The system cannot find the file specified. \r\n"
L"Error code: Wsl/Service/AttachDisk/MountDisk/HCS/ERROR_FILE_NOT_FOUND\r\n");
FormatErrorMessage(
L"Failed to attach disk 'DoesNotExist' to WSL2: The system cannot find the file specified. ",
L"Wsl/Service/AttachDisk/MountDisk/HCS/ERROR_FILE_NOT_FOUND"));
}

WSL2_TEST_METHOD(MountPolicyDisabled)
Expand All @@ -120,7 +121,7 @@ class PolicyTest
auto revert = SetPolicy(c_allowDiskMount, 0);
ValidateOutput(
L"--mount DoesNotExist",
L"wsl.exe --mount is disabled by the computer policy.\r\nError code: Wsl/Service/WSL_E_DISK_MOUNT_DISABLED\r\n");
FormatErrorMessage(L"wsl.exe --mount is disabled by the computer policy.", L"Wsl/Service/WSL_E_DISK_MOUNT_DISABLED"));
}

void ValidatePolicy(LPCWSTR Name, LPCWSTR Config, LPCWSTR ExpectedWarnings, const std::function<void(DWORD)>& Validate = [](auto) {})
Expand Down Expand Up @@ -210,9 +211,9 @@ class PolicyTest

ValidateOutput(
L"echo ok",
std::format(
L"{}\r\nError code: Wsl/Service/CreateInstance/CreateVm/WSL_E_CUSTOM_KERNEL_NOT_FOUND\r\n",
wsl::shared::Localization::MessageCustomKernelNotFound(wslConfigPath, nonExistentFile)));
FormatErrorMessage(
wsl::shared::Localization::MessageCustomKernelNotFound(wslConfigPath, nonExistentFile),
L"Wsl/Service/CreateInstance/CreateVm/WSL_E_CUSTOM_KERNEL_NOT_FOUND"));
}

// Disable the custom kernel policy and validate that the expected warnings are shown.
Expand Down Expand Up @@ -246,9 +247,9 @@ class PolicyTest

ValidateOutput(
L"echo ok",
L"The custom system distribution specified in " + wslConfigPath +
L" was not found or is not the correct format.\r\nError code: "
L"Wsl/Service/CreateInstance/CreateVm/WSL_E_CUSTOM_SYSTEM_DISTRO_ERROR\r\n");
FormatErrorMessage(
L"The custom system distribution specified in " + wslConfigPath + L" was not found or is not the correct format.",
L"Wsl/Service/CreateInstance/CreateVm/WSL_E_CUSTOM_SYSTEM_DISTRO_ERROR"));
}

{
Expand Down Expand Up @@ -321,13 +322,16 @@ class PolicyTest
{
ValidateOutput(
L"--set-version " LXSS_DISTRO_NAME_TEST_L L" 1",
L"WSL1 is disabled by the computer policy.\r\nError code: Wsl/Service/WSL_E_WSL1_DISABLED\r\n");
FormatErrorMessage(L"WSL1 is disabled by the computer policy.", L"Wsl/Service/WSL_E_WSL1_DISABLED"));
}
else
{
ValidateOutput(
L"echo ok",
L"WSL1 is disabled by the computer policy.\r\nPlease run 'wsl.exe --set-version " LXSS_DISTRO_NAME_TEST_L L" 2' to upgrade to WSL2.\r\nError code: Wsl/Service/CreateInstance/WSL_E_WSL1_DISABLED\r\n");
L"echo ok",
FormatErrorMessage(
L"WSL1 is disabled by the computer policy.\r\nPlease run 'wsl.exe "
L"--set-version " LXSS_DISTRO_NAME_TEST_L L" 2' to upgrade to WSL2.",
L"Wsl/Service/CreateInstance/WSL_E_WSL1_DISABLED"));
}
}
}
Expand Down Expand Up @@ -361,9 +365,9 @@ class PolicyTest
auto [output, _] = LxsstuLaunchWslAndCaptureOutput(L"/bin/true", -1);
VERIFY_ARE_EQUAL(
output,
L"This program is blocked by group policy. For more information, contact your system administrator. "
L"\r\nError "
L"code: Wsl/ERROR_ACCESS_DISABLED_BY_POLICY\r\n");
FormatErrorMessage(
L"This program is blocked by group policy. For more information, contact your system administrator. ",
L"Wsl/ERROR_ACCESS_DISABLED_BY_POLICY"));
}
};

Expand Down Expand Up @@ -456,10 +460,10 @@ class PolicyTest
// The disabled message must go to stderr only -- never to stdout.
VERIFY_ARE_EQUAL(L"", stdoutText);

// The wslc CLI renders failures via MessageErrorCode("{}\nError code: {}") and
// The wslc CLI renders failures via MessageErrorCode and
// PrintMessage adds a trailing newline; line endings are \r\n through console pipes.
const auto expected =
wsl::shared::Localization::MessageWSLContainerDisabled() + L"\r\nError code: WSLC_E_CONTAINER_DISABLED\r\n";
FormatErrorMessage(wsl::shared::Localization::MessageWSLContainerDisabled(), L"WSLC_E_CONTAINER_DISABLED");
VERIFY_ARE_EQUAL(expected, stderrText);
}

Expand All @@ -476,8 +480,8 @@ class PolicyTest
VERIFY_ARE_NOT_EQUAL(0, exitCode);
VERIFY_ARE_EQUAL(L"", stdoutText);

const auto expected = wsl::shared::Localization::MessageRegistryBlockedByPolicy(L"docker.io") +
L"\r\nError code: WSLC_E_REGISTRY_BLOCKED_BY_POLICY\r\n";
const auto expected = FormatErrorMessage(
wsl::shared::Localization::MessageRegistryBlockedByPolicy(L"docker.io"), L"WSLC_E_REGISTRY_BLOCKED_BY_POLICY");
VERIFY_ARE_EQUAL(expected, stderrText);
}

Expand Down
8 changes: 5 additions & 3 deletions test/windows/SimpleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ class SimpleTests
// Setting a distro VHD to sparse requires the allow unsafe flag.
ValidateOutput(
std::format(L"{} {} {} {}", WSL_MANAGE_ARG, tempDistro, WSL_MANAGE_ARG_SET_SPARSE_OPTION_LONG, L"true").c_str(),
L"Sparse VHD support is currently disabled due to potential data corruption.\r\n"
L"To force a distribution to use a sparse VHD, please run:\r\n"
L"wsl.exe --manage <DistributionName> --set-sparse true --allow-unsafe\r\nError code: Wsl/Service/E_INVALIDARG\r\n",
FormatErrorMessage(
L"Sparse VHD support is currently disabled due to potential data corruption.\r\n"
L"To force a distribution to use a sparse VHD, please run:\r\n"
L"wsl.exe --manage <DistributionName> --set-sparse true --allow-unsafe",
L"Wsl/Service/E_INVALIDARG"),
L"",
-1);

Expand Down
Loading