Use IsErrNotFound to tighten err handling

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
Riyaz Faizullabhoy 2017-04-28 10:50:58 -07:00
parent d504afe479
commit 95a9a4ff67

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/docker/docker/client"
) )
// This uses Docker to convert a Docker image into a tarball. It would be an improvement if we // This uses Docker to convert a Docker image into a tarball. It would be an improvement if we
@ -102,7 +103,8 @@ func imageTar(image, prefix string, tw *tar.Writer, trust bool, pull bool) error
} }
container, err := dockerCreate(image) container, err := dockerCreate(image)
if err != nil { if err != nil {
// most likely we need to pull the image if this failed // if the image wasn't found, pull it down. Bail on other errors.
if client.IsErrNotFound(err) {
log.Infof("Pull image: %s", image) log.Infof("Pull image: %s", image)
err := dockerPull(image, trust) err := dockerPull(image, trust)
if err != nil { if err != nil {
@ -113,6 +115,9 @@ func imageTar(image, prefix string, tw *tar.Writer, trust bool, pull bool) error
return fmt.Errorf("Failed to docker create image %s: %v", image, err) return fmt.Errorf("Failed to docker create image %s: %v", image, err)
} }
} }
return fmt.Errorf("Failed to create docker image %s: %v", image, err)
}
contents, err := dockerExport(container) contents, err := dockerExport(container)
if err != nil { if err != nil {
return fmt.Errorf("Failed to docker export container from container %s: %v", container, err) return fmt.Errorf("Failed to docker export container from container %s: %v", container, err)