Skip to content

Commit 6f60b8c

Browse files
committed
Localize port-conflict error
1 parent d07eb74 commit 6f60b8c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

localization/strings/en-US/Resources.resw

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,10 @@ For privacy information about this product please visit https://aka.ms/privacy.<
21102110
<value>Volume '{}' is in use.</value>
21112111
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
21122112
</data>
2113+
<data name = "MessageWslcPortInUse" xml:space = "preserve" >
2114+
<value>Port {} is already in use, cannot start container {}</value>
2115+
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
2116+
</data>
21132117
<data name = "MessageWslcBothDockerAndContainerFileFound" xml:space = "preserve" >
21142118
<value>Both Dockerfile and Containerfile found. Use -f to select the file to use</value>
21152119
<comment>{FixedPlaceholder="Dockerfile"}{FixedPlaceholder="Containerfile"}{FixedPlaceholder="-f"}Command line arguments, file names and string inserts should not be translated</comment>

src/windows/wslcsession/WSLCContainer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,12 @@ std::unique_ptr<WSLCContainerImpl> WSLCContainerImpl::Open(
12741274
{
12751275
auto allocation = virtualMachine.TryAllocatePort(e.VmPort, e.Family, e.Protocol);
12761276

1277-
THROW_HR_WITH_USER_ERROR_IF(
1277+
THROW_HR_IF_MSG(
12781278
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
1279-
std::format(L"Port {} is already in use, cannot open container {}", e.VmPort, dockerContainer.Id),
1280-
!allocation);
1279+
!allocation,
1280+
"Port %hu is in use, cannot open container %hs",
1281+
e.VmPort,
1282+
dockerContainer.Id.c_str());
12811283

12821284
inserted.VmMapping.AssignVmPort(allocation);
12831285
}
@@ -1443,7 +1445,8 @@ void WSLCContainerImpl::MapPorts()
14431445

14441446
THROW_HR_WITH_USER_ERROR_IF(
14451447
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
1446-
std::format(L"Port {} is already in use, cannot start container {}", e.VmMapping.HostPort(), m_id),
1448+
wsl::shared::Localization::MessageWslcPortInUse(
1449+
std::format("{}:{}/{}", e.VmMapping.BindingAddressString(), e.VmMapping.HostPort(), e.ProtocolString()), m_id),
14471450
!allocatedPort);
14481451

14491452
e.VmMapping.AssignVmPort(allocatedPort);
@@ -1462,7 +1465,8 @@ void WSLCContainerImpl::MapPorts()
14621465
{
14631466
THROW_HR_WITH_USER_ERROR(
14641467
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
1465-
std::format(L"Port {} is already in use, cannot start container {}", e.VmMapping.HostPort(), m_id));
1468+
wsl::shared::Localization::MessageWslcPortInUse(
1469+
std::format("{}:{}/{}", e.VmMapping.BindingAddressString(), e.VmMapping.HostPort(), e.ProtocolString()), m_id));
14661470
}
14671471
throw;
14681472
}

0 commit comments

Comments
 (0)