Skip to content

Conversation

@zaineel
Copy link

@zaineel zaineel commented Dec 22, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

The stop and kill commands currently do not gracefully handle cases where container IDs are missing or not found. This PR adds proper error handling for missing containers and ensures validation tests run correctly.

Fixes #878

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@zaineel
Copy link
Author

zaineel commented Dec 23, 2025

@dcantah
Could you please take a look at this PR? Thanks!

let allContainers = try await ClientContainer.list()
let containers = try self.all
? allContainers
: Self.containers(matching: containerIds, in: allContainers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should handle ambiguous prefix matches here.

Currently, allContainers.first(where:) will silently pick the first matching container. If I have containers abc and abd, running stop ab might stop abc just because it appears first in the list.

It would be safer to filter all matches and throw an error if matches.count > 1 (unless there's an exact match). This aligns with how Docker handles ambiguous prefixes.


@testable import ContainerCommands

struct ContainerStopValidationTests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test case for ambiguous prefixes?

We should verify that stop ab throws an error if both abc and abd exist. It's an important edge case to prevent accidental stops.

import ContainerizationOS
import Foundation

package protocol ContainerIdentifiable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring this resolution logic into a shared helper is a great move. It keeps Stop and Kill consistent and makes testing way easier.

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