Skip to content

feat: error on unknown service name in up instead of hanging - #139

Merged
Cyb3rDudu merged 1 commit into
Mcrich23:mainfrom
OrtegaMatias:feat/no-such-service-validation
Jul 23, 2026
Merged

Cyb3rDudu merged 1 commit into
Mcrich23:mainfrom
OrtegaMatias:feat/no-such-service-validation

Conversation

@OrtegaMatias

Copy link
Copy Markdown
Contributor

Summary

container-compose up <service> silently selected nothing when <service> wasn't defined in the compose file (a typo, or a service that was renamed/removed). In foreground mode (up without -d), it then blocked forever in runForegroundUntilStopped, waiting on containers that were never created — so a mistyped service name looked like a hang.

This validates requested service names up front and fails fast with no such service: <name>, matching docker compose up <svc>.

Reproduce (before)

$ container-compose up nginx-typo      # nginx-typo not in compose
# …hangs indefinitely, no output, has to be Ctrl-C'd

After

$ container-compose up nginx-typo
Error: no such service: nginx-typo

Verified end-to-end against a real ~30-service compose file: the unknown name now errors immediately, and a valid service name proceeds unchanged.

Changes

  • Add ComposeError.noSuchService(String) → "no such service: <name>".
  • Add Service.validateRequestedServices(_:against:) and call it in ComposeUp.run() right after the service list is built (before profile selection).
  • Add unit tests in Container-Compose-StaticTests covering: all-exist passes, empty request passes, unknown throws, the error wording, and first-unknown-wins.

Tests

swift test --filter Container_Compose_StaticTests → 215 tests, 20 suites, 0 failures (same command the CI runs).

No behavior change for valid service names; purely additive validation.

@Cyb3rDudu

Cyb3rDudu commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto latest main (includes #129 + #138) and pushed to the PR branch.

Changes vs original PR:

  • Validation now runs after projectOptions.resolve() since topo-sort/select moved into the shared layer ( Add shared ComposeProjectOptions #138)
  • Validates against all compose services (pre-profile filtering) so explicit profile-gated names still work
  • Removed redundant print warning in ComposeProject.orderedServices() since this hard error supersedes it

All 236 static tests pass (0 failures).

`container-compose up <service>` silently selected nothing when
<service> was not defined in the compose file (a typo, or a service
removed from the file). In foreground mode `up` then blocked forever in
`runForegroundUntilStopped`, waiting on containers that were never
created — so a mistyped service name looked like a hang.

Validate requested service names up front and fail with
`no such service: <name>`, matching `docker compose up <svc>`.

Adds `ComposeError.noSuchService` and unit tests for
`Service.validateRequestedServices`.
@Cyb3rDudu
Cyb3rDudu force-pushed the feat/no-such-service-validation branch from 04f8d77 to e22aaf0 Compare July 23, 2026 03:04
@Cyb3rDudu
Cyb3rDudu merged commit 6e6aaf0 into Mcrich23:main Jul 23, 2026
1 check passed
@OrtegaMatias
OrtegaMatias deleted the feat/no-such-service-validation branch July 28, 2026 06:59
Mcrich23 pushed a commit that referenced this pull request Nov 10, 2026
* Add pull subcommand to fetch service images from a compose file

Pulls each resolved service's image, skipping build-only services (no
image key) and images already present locally — mirroring the
already-present match logic up uses (exact, registry-prefixed, or
short reference). Passes the service's platform: through when set.

Resolves the project through the shared ComposeProjectOptions (#138)
and fails fast on unknown service names per the #139 contract.

* fix(pull): always pull, resolve image variables, and pull only requested services

- Drop the already-present shortcut: refreshing a moving tag like
  :latest is the point of an explicit pull (up's implicit pull keeps
  the shortcut).
- Resolve ${VAR}/${VAR:-default} placeholders in image references
  from the environment file before pulling — a literal ${...} is not
  a valid registry reference.
- Pull only the requested services' images: the shared selection
  expands depends_on for up's sake, so explicit requests are narrowed
  back to the named services, with --include-deps to opt into the
  expanded set (matching docker compose pull).

Extracts pullTargets/resolvedImage as pure functions with unit
coverage for dependency narrowing, --include-deps, variable
resolution and defaults, and build-only services.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Lists the compose project's containers in an aligned
NAME/IMAGE/STATUS/PORTS table, showing only running containers unless
-a/--all is passed. Containers are matched primarily by the
com.docker.compose.project/service labels stamped since Mcrich23#126 (reliable
across naming modes), falling back to the candidate container names for
containers created before the labels existed.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138)
and fails fast on unknown service names with the noSuchService
contract Mcrich23#139 established for up.
Mcrich23 pushed a commit that referenced this pull request Nov 14, 2026
* Add ps subcommand to list project containers

Lists the compose project's containers in an aligned
NAME/IMAGE/STATUS/PORTS table, showing only running containers unless
-a/--all is passed. Containers are matched primarily by the
com.docker.compose.project/service labels stamped since #126 (reliable
across naming modes), falling back to the candidate container names for
containers created before the labels existed.

Resolves the project through the shared ComposeProjectOptions (#138)
and fails fast on unknown service names with the noSuchService
contract #139 established for up.

* fix(ps): limit the name fallback to unlabeled containers

A container labeled for a different project could be included when its
name collided with one of our candidate names (e.g. project demo +
service web-x produce the candidate demo-web-x, which is also the name
project demo-web gives its service x). Labels are now authoritative
whenever present; the candidate-name fallback applies only to
containers without compose labels (created before #126 stamped them).

Extracts the selection into ComposePs.select, generic over the
container representation, with unit coverage for project filtering,
service filtering, the unlabeled fallback, and stopped-container
visibility with and without --all.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Implements exec SERVICE COMMAND [ARG...] like docker compose exec:
resolves the single requested service through the shared
ComposeProjectOptions (Mcrich23#138), finds its container by the
com.docker.compose project/service labels (candidate-name fallback for
pre-label containers; a container labeled for another project is never
selected), verifies it is running, and shells out to container exec
with the terminal's stdio inherited so interactive sessions (-i/-t)
work. Maps the shared process flags (user, workdir, env, env-file)
onto container exec; --index is accepted as a docker parity no-op
since replicas are unsupported. Fails fast on unknown service names
per the Mcrich23#139 contract.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Streams container logs for the project's services concurrently, each
line prefixed with its padded, color-coded service name (--no-color /
--no-log-prefix to disable; the palette matches up's). Supports
--follow and --tail. --follow is long-only because -f is owned
tool-wide by --file.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138),
fails fast on unknown service names per the Mcrich23#139 contract, and shows
only the named services on explicit requests (dependencies are not
pulled in, matching docker compose logs). Containers are matched by
the com.docker.compose project/service labels with a candidate-name
fallback for pre-label containers.

Adds a shared streamSubprocess helper for line-streaming a child
process; ComposeUp keeps its private equivalent for now — unifying
them is deferred while several open PRs rework ComposeUp's process
handling.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Lists each service's backing image as SERVICE/REPOSITORY/TAG, deriving
the repository and tag from service.image (or the built
<service>:latest tag for build-only services) and best-effort
cross-referencing ClientImage.list() for IMAGE ID and SIZE.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138),
fails fast on unknown service names per the Mcrich23#139 contract, and reuses
the ps table renderer.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Implements exec SERVICE COMMAND [ARG...] like docker compose exec:
resolves the single requested service through the shared
ComposeProjectOptions (Mcrich23#138), finds its container by the
com.docker.compose project/service labels (candidate-name fallback for
pre-label containers; a container labeled for another project is never
selected), verifies it is running, and shells out to container exec
with the terminal's stdio inherited so interactive sessions (-i/-t)
work. Maps the shared process flags (user, workdir, env, env-file)
onto container exec; --index is accepted as a docker parity no-op
since replicas are unsupported. Fails fast on unknown service names
per the Mcrich23#139 contract.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Streams container logs for the project's services concurrently, each
line prefixed with its padded, color-coded service name (--no-color /
--no-log-prefix to disable; the palette matches up's). Supports
--follow and --tail. --follow is long-only because -f is owned
tool-wide by --file.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138),
fails fast on unknown service names per the Mcrich23#139 contract, and shows
only the named services on explicit requests (dependencies are not
pulled in, matching docker compose logs). Containers are matched by
the com.docker.compose project/service labels with a candidate-name
fallback for pre-label containers.

Adds a shared streamSubprocess helper for line-streaming a child
process; ComposeUp keeps its private equivalent for now — unifying
them is deferred while several open PRs rework ComposeUp's process
handling.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
stop halts running service containers without removing them, in
reverse dependency order and honoring each service's
stop_grace_period (Mcrich23#150); start boots them back up in dependency
order via container start. Both resolve the project through the
shared ComposeProjectOptions, find containers with the shared
label-first matching rule, fail fast on unknown service names per
the Mcrich23#139 contract, and act only on explicitly named services
(dependencies are not expanded, matching docker compose stop/start).
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
restart stops each service container in place — honoring its
stop_grace_period (Mcrich23#150) — and boots it again via container start,
in dependency order. kill force-stops containers with a signal
(-s/--signal, SIGKILL by default; names accepted with or without the
SIG prefix, or numeric), in reverse dependency order. Both resolve
the project through the shared ComposeProjectOptions, find containers
with the shared label-first matching rule, fail fast on unknown
service names per the Mcrich23#139 contract, and act only on explicitly named
services, matching docker compose restart/kill.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
stop halts running service containers without removing them, in
reverse dependency order and honoring each service's
stop_grace_period (Mcrich23#150); start boots them back up in dependency
order via container start. Both resolve the project through the
shared ComposeProjectOptions, find containers with the shared
label-first matching rule, fail fast on unknown service names per
the Mcrich23#139 contract, and act only on explicitly named services
(dependencies are not expanded, matching docker compose stop/start).
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Streams container logs for the project's services concurrently, each
line prefixed with its padded, color-coded service name (--no-color /
--no-log-prefix to disable; the palette matches up's). Supports
--follow and --tail. --follow is long-only because -f is owned
tool-wide by --file.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138),
fails fast on unknown service names per the Mcrich23#139 contract, and shows
only the named services on explicit requests (dependencies are not
pulled in, matching docker compose logs). Containers are matched by
the com.docker.compose project/service labels with a candidate-name
fallback for pre-label containers.

Adds a shared streamSubprocess helper for line-streaming a child
process; ComposeUp keeps its private equivalent for now — unifying
them is deferred while several open PRs rework ComposeUp's process
handling.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
Implements exec SERVICE COMMAND [ARG...] like docker compose exec:
resolves the single requested service through the shared
ComposeProjectOptions (Mcrich23#138), finds its container by the
com.docker.compose project/service labels (candidate-name fallback for
pre-label containers; a container labeled for another project is never
selected), verifies it is running, and shells out to container exec
with the terminal's stdio inherited so interactive sessions (-i/-t)
work. Maps the shared process flags (user, workdir, env, env-file)
onto container exec; --index is accepted as a docker parity no-op
since replicas are unsupported. Fails fast on unknown service names
per the Mcrich23#139 contract.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 14, 2026
restart stops each service container in place — honoring its
stop_grace_period (Mcrich23#150) — and boots it again via container start,
in dependency order. kill force-stops containers with a signal
(-s/--signal, SIGKILL by default; names accepted with or without the
SIG prefix, or numeric), in reverse dependency order. Both resolve
the project through the shared ComposeProjectOptions, find containers
with the shared label-first matching rule, fail fast on unknown
service names per the Mcrich23#139 contract, and act only on explicitly named
services, matching docker compose restart/kill.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 25, 2026
Implements exec SERVICE COMMAND [ARG...] like docker compose exec:
resolves the single requested service through the shared
ComposeProjectOptions (Mcrich23#138), finds its container by the
com.docker.compose project/service labels (candidate-name fallback for
pre-label containers; a container labeled for another project is never
selected), verifies it is running, and shells out to container exec
with the terminal's stdio inherited so interactive sessions (-i/-t)
work. Maps the shared process flags (user, workdir, env, env-file)
onto container exec; --index is accepted as a docker parity no-op
since replicas are unsupported. Fails fast on unknown service names
per the Mcrich23#139 contract.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 25, 2026
Streams container logs for the project's services concurrently, each
line prefixed with its padded, color-coded service name (--no-color /
--no-log-prefix to disable; the palette matches up's). Supports
--follow and --tail. --follow is long-only because -f is owned
tool-wide by --file.

Resolves the project through the shared ComposeProjectOptions (Mcrich23#138),
fails fast on unknown service names per the Mcrich23#139 contract, and shows
only the named services on explicit requests (dependencies are not
pulled in, matching docker compose logs). Containers are matched by
the com.docker.compose project/service labels with a candidate-name
fallback for pre-label containers.

Adds a shared streamSubprocess helper for line-streaming a child
process; ComposeUp keeps its private equivalent for now — unifying
them is deferred while several open PRs rework ComposeUp's process
handling.
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 25, 2026
stop halts running service containers without removing them, in
reverse dependency order and honoring each service's
stop_grace_period (Mcrich23#150); start boots them back up in dependency
order via container start. Both resolve the project through the
shared ComposeProjectOptions, find containers with the shared
label-first matching rule, fail fast on unknown service names per
the Mcrich23#139 contract, and act only on explicitly named services
(dependencies are not expanded, matching docker compose stop/start).
adrum added a commit to adrum/Container-Compose that referenced this pull request Nov 25, 2026
restart stops each service container in place — honoring its
stop_grace_period (Mcrich23#150) — and boots it again via container start,
in dependency order. kill force-stops containers with a signal
(-s/--signal, SIGKILL by default; names accepted with or without the
SIG prefix, or numeric), in reverse dependency order. Both resolve
the project through the shared ComposeProjectOptions, find containers
with the shared label-first matching rule, fail fast on unknown
service names per the Mcrich23#139 contract, and act only on explicitly named
services, matching docker compose restart/kill.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants