From c49ad43aa3e099a20891a63e191ea7da3471b654 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 17 Dec 2021 10:44:27 +0530 Subject: [PATCH] Containerd Logging and error handling (#7) Co-authored-by: Saurabh --- containerd/containerd.go | 4 ++++ docker/docker.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/containerd/containerd.go b/containerd/containerd.go index b9b946b..6524f37 100644 --- a/containerd/containerd.go +++ b/containerd/containerd.go @@ -171,6 +171,10 @@ func (c Containerd) ExtractFileSystem(imageTarPath string, outputTarPath string, fmt.Println("Error while Importing image") return err } + if len(imgs) == 0 { + fmt.Printf("No images imported, imageTarPath: %s, outputTarPath: %s, imageName: %s \n", imageTarPath, outputTarPath, imageName) + return errors.New("image not imported from: " + imageTarPath) + } image, err := client.GetImage(ctx, imgs[0].Name) if err != nil { fmt.Println("Error while getting image from client") diff --git a/docker/docker.go b/docker/docker.go index 4891c2c..d2baa56 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -74,7 +74,7 @@ func (d Docker) ExtractFileSystem(imageTarPath string, outputTarPath string, ima for scanner.Scan() { line := scanner.Text() if strings.Contains(line, "Loaded image") { - splits := strings.SplitAfterN(line,":", 2) + splits := strings.SplitAfterN(line, ":", 2) if len(splits) > 1 { imageId = strings.TrimSpace(splits[1]) break