Skip to content

bug: import-dir exits 0 after partial artifact import failures #379

@cotishq

Description

@cotishq

Describe the bug

microcks import-dir can report failed artifact imports but still complete with exit code 0.

The command already tracks failed imports through ImportResult.FailedCount, but after printing the final import summary it does not return a non-zero exit code when FailedCount > 0.

This is problematic for scripts and CI pipelines because a partial import failure is treated as a successful command execution.

Expected behavior

When one or more files fail to import, microcks import-dir should:

  • continue processing the remaining files
  • print the import summary
  • exit with a non-zero status code, for example 1

If all files are imported successfully, it should continue exiting with status code 0.

Actual behavior

When ImportDirectory completes with partial failures, the command prints the failed files and final summary, but then returns normally.

Because the Cobra command returns without calling os.Exit(1) or returning an error, the process exits with status code 0.

Image

How to Reproduce?

This can be observed from the current command flow in cmd/importDir.go.

Reproducer:

  1. Make ImportDirectory process multiple specification files.
  2. Have one UploadArtifact call fail while another succeeds.
  3. ImportDirectory returns a result with FailedCount > 0 and err == nil.
  4. NewImportDirCommand prints the summary but does not check result.FailedCount.
  5. The command returns normally, so the process exits with status code 0.

The existing unit test TestImportDirectory/partial_failure already demonstrates the partial-failure case at the business-logic level: one file succeeds, one file fails, and FailedCount is set to 1.

Resources to reproduce the behaviour:

  1. cmd/importDir.go
  2. cmd/importDir_test.go
  3. Existing test case: TestImportDirectory/partial_failure

Microcks version or git rev

Microcks-CLI 1.0.2

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

A possible fix is to check result.FailedCount after printing the summary:

if result.FailedCount > 0 {
    os.Exit(1)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions