Skip to content

feat(container): add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 - #175

Open
kw-00 wants to merge 5 commits into
docker:mainfrom
kw-00:issue-155
Open

kw-00 wants to merge 5 commits into
docker:mainfrom
kw-00:issue-155

Conversation

@kw-00

@kw-00 kw-00 commented Oct 28, 2026 •

Copy link
Copy Markdown

What does this PR do?

I added a variant of WithStartupCommand called "WithStrictStartupCommand" as well as a variant of WithAfterReadyCommand called "WithStrictAfterReadyCommand".

These variants preserve the behaviour of the original functions, except that they treat non-zero exit codes in executable commands as errors. Those errors are eventually returned via container.Run().

I decided to do this by introducing a variant of the helper function named createExecutableHooks(). The variant, named createStrictExecutableHooks, is then used in the With... functions.

I also added tests for this new functionality.

The change was inspired by issue #155 . I decided to create new functions instead of modifying the original WithStartupCommand and WithAfterReadyCommand for the following reasons:

  • doing the latter would cause a breaking change
  • it is reasonably possible that a user would prefer no errors to be reported
  • treating exit codes as normal errors makes them difficult to distinguish from Exec-specific errors without further changes (such as a special go-sdk error type)

Why is it important?

The core problem is explained in issue #155 . When an executable command is hooked using WithStartupCommand or WithAfterReadyCommand, its exit status is ignored.

This causes a container to start "successfully", even though its startup/after-ready commands may have failed.

Related issues

Closes #155

How to test this PR

Tests for the new functionality have been added to container/container.run_test.go. No current functionality depends on these changes.

Follow-ups

It would be possible to deduplicate test code in container/container.run_test.go and also deduplicate logic in the With... functions used for registering hooks, though this could sacrifice straightforwardness.

kw-00 added 4 commits October 28, 2026 14:00
These two functions are variants to WithStartupCommand and WithAfterReadyCommand, respectively. As opposed to the latter, they treat non-zero exit codes from executable commands as errors.

The variants are implemented just like the original functions, except that they use createStrictExecutableHooks instead of createExecutableHooks.
createStrictExecutableHooks is a variant of createExecutableHooks which treats non-zero exit codes as errors and has also been implemented as part of this commit.
…dyCommand

For both features, the tests include the following:
- command execution and io tests analogical to those found in WithStartupCommand and WithStrictAfterReadyCommand, respectively
- test that expects an error when executable command finishes with a non-zero exit code - this is the new functionality that WithStrict... functions add
@kw-00 kw-00 changed the title Add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 feat: add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 Oct 28, 2026
@kw-00 kw-00 changed the title feat: add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 feat(container): add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 Oct 28, 2026
…mmand

These tests merely check whether no error occurs when WithStrictStartupCommand and WithStrictAfterReadyCommand are used to register hooks
and also whether the hooks actually gets registered.

I am adding them because tests using the same logic already exist for the original WithStartupCommand and WithAfterReadyCommand,
so it might be expected that the variants added in this PR are also tested for this.

These tests do not test any new functionality. The new functionality of treating non-zero exit codes as errors is a feature used when running containers,
and I have already added tests for this in container/container.run_test.go.
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.

WithStartupCommand silently swallows non-zero exit codes from the inner command

1 participant