Browse code

Fix a regression in `docker import` on error from URL

when the daemon can't download the image from a `docker import` the
error message was lost due to 'err' being redefined with a block by
mistake. This removes the ":" from "... err := " which fixes it.

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/05/14 09:21:02
Showing 2 changed files
... ...
@@ -717,14 +717,17 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
717 717
 			OutStream: output,
718 718
 		}
719 719
 
720
-		newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
720
+		// 'err' MUST NOT be defined within this block, we need any error
721
+		// generated from the download to be available to the output
722
+		// stream processing below
723
+		var newConfig *runconfig.Config
724
+		newConfig, err = builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
721 725
 		if err != nil {
722 726
 			return err
723 727
 		}
724 728
 		imageImportConfig.ContainerConfig = newConfig
725 729
 
726 730
 		err = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig)
727
-
728 731
 	}
729 732
 	if err != nil {
730 733
 		if !output.Flushed() {
... ...
@@ -39,3 +39,14 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
39 39
 	}
40 40
 
41 41
 }
42
+
43
+func (s *DockerSuite) TestImportBadURL(c *check.C) {
44
+	runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
45
+	out, _, err := runCommandWithOutput(runCmd)
46
+	if err == nil {
47
+		c.Fatal("import was supposed to fail but didn't")
48
+	}
49
+	if !strings.Contains(out, "dial tcp") {
50
+		c.Fatalf("expected an error msg but didn't get one:\n%s", out)
51
+	}
52
+}