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

feat: error on unknown service name in up instead of hanging#139
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_StaticTests215 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
Collaborator

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