From 17d122e1e311a5bb752729bcf4e6aa40c016b99d Mon Sep 17 00:00:00 2001 From: Aditya Date: Sat, 16 May 2026 19:43:22 +0530 Subject: [PATCH] fix: continue importing remaining artifacts on failure Previously, the import command would exit immediately on the first failed artifact, leaving remaining files unprocessed. Now all artifacts are attempted and a non-zero exit code is returned only if any import failed. Closes #393 Signed-off-by: Aditya --- cmd/import.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/import.go b/cmd/import.go index c1a74c4c..bf07a851 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -114,6 +114,7 @@ func NewImportCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command return } } + var hasErrors bool // Handle multiple specification files separated by comma. sepSpecificationFiles := strings.Split(specificationFiles, ",") @@ -132,16 +133,17 @@ func NewImportCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command } // Try uploading this artifact. - msg, err := mc.UploadArtifact(f, mainArtifact) - if err != nil { - fmt.Printf("Got error when invoking Microcks client importing Artifact: %s", err) - os.Exit(1) - } - action := "discovered" - if !mainArtifact { - action = "completed" - } - fmt.Printf("Microcks has %s '%s'\n", action, msg) + msg, err := mc.UploadArtifact(f, mainArtifact) + if err != nil { + fmt.Printf("Failed to import '%s': %s\n", f, err) + hasErrors = true + continue + } + action := "discovered" + if !mainArtifact { + action = "completed" + } + fmt.Printf("Microcks has %s '%s'\n", action, msg) // If watch flag is provided, update watch config. if watch { @@ -155,9 +157,8 @@ func NewImportCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command } // Normalize file path to match the watcher fsnotify events format. - if strings.HasPrefix(f, "./") { - f = strings.TrimPrefix(f, "./") - } + + f = strings.TrimPrefix(f, "./") // Upsert entry. watchCfg.UpsertEntry(config.WatchEntry{ @@ -171,6 +172,9 @@ func NewImportCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command errors.CheckError(err) } } + if hasErrors { + os.Exit(1) + } // Start watcher if --watch flag is provided. if watch {