fix(types): name the clashing service and make the error stable - #908
Open
AlbertEinsteinTG wants to merge 1 commit into
Open
fix(types): name the clashing service and make the error stable#908AlbertEinsteinTG wants to merge 1 commit into
AlbertEinsteinTG wants to merge 1 commit into
Conversation
CheckContainerNameUnicity tracked seen container names in a
utils.Set[string], which is a map[string]struct{}. Indexing it yields
the zero struct rather than the service that claimed the name, so the
%s verb rendered it as "{}". The format string also ended with an
unbalanced quote:
services.a: container name "shared" is already in use by service {}"
Track container_name -> declaring service in a map[string]string and
print it with %q so both services are named. Iterate via ServiceNames()
instead of ranging over the map: Go randomises map iteration, so the
same project surfaced a different pair on each run, which made the
error unreproducible in bug reports and impossible to assert exactly.
services.a: container name "shared" is already in use by service "b"
The existing test asserted a substring ending one word before the
broken segment, so neither defect was covered. It now asserts the
whole message, which the stable ordering makes possible.
Signed-off-by: Ben S George <73480087+AlbertEinsteinTG@users.noreply.github.com>
AlbertEinsteinTG
force-pushed
the
fix/container-name-clash-error
branch
from
August 9, 2026 12:16
054b901 to
dd04613
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When two services declare the same
container_name, the error names neitherthe conflicting service nor anything actionable:
Two defects in one line:
{}instead of the other service's name."at the end.And a third, related issue: the message is not deterministic. The same
project reports a different service on each run.
Reproduce
docker compose config, six consecutive runs, no changes in between:Docker Compose v5.1.3 (vendoring compose-go v2.10.2). Reproduces on
main.Cause
types/project.go:utils/set.go:existingis the map value —struct{}{}— not the service that claimedthe name, and
%srenders an empty struct as{}. ASetstructurally cannotcarry the owning service, so this never worked. The trailing
"looks like aleftover from
"%s"that lost its opening quote.The non-determinism comes from
range p.Services: Go randomises map iteration,so which service is recorded first, and therefore which is reported as the
offender, varies per run.
Change
container_name -> declaring servicein amap[string]stringso theconflicting service can be named.
%q, which supplies the quotes and drops the stray one.ServiceNames()(already in this file, returns sorted names) sothe reported pair is stable.
After:
Tests
The existing assertion stopped one word before the broken segment:
so everything after
is already in use bywas unverified — which is how bothdefects survived. It now asserts the full message, which the stable ordering
makes possible.
Notes
CheckContainerNameUnicity's signature and error semantics areunchanged; only the message text and its stability.
fix(interpolation): report all errors in a deterministic order—same root cause (randomised map iteration producing a different message per
run). Happy to split this into two commits if you'd prefer them reviewed
separately.