1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #12649 from jlhawn/fix_pull_err_explosion

Correctly format API error on image pull
This commit is contained in:
Doug Davis 2015-04-22 20:28:24 -04:00
commit 5ea8dc376c
2 changed files with 25 additions and 20 deletions

View file

@ -738,6 +738,15 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
}
}
var (
opErr error
useJSON = version.GreaterThan("1.0")
)
if useJSON {
w.Header().Set("Content-Type", "application/json")
}
if image != "" { //pull
if tag == "" {
image, tag = parsers.ParseRepositoryTag(image)
@ -754,17 +763,10 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
MetaHeaders: metaHeaders,
AuthConfig: authConfig,
OutStream: utils.NewWriteFlusher(w),
}
if version.GreaterThan("1.0") {
imagePullConfig.Json = true
w.Header().Set("Content-Type", "application/json")
} else {
imagePullConfig.Json = false
Json: useJSON,
}
if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig); err != nil {
return err
}
opErr = s.daemon.Repositories().Pull(image, tag, imagePullConfig)
} else { //import
if tag == "" {
repo, tag = parsers.ParseRepositoryTag(repo)
@ -775,12 +777,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
Changes: r.Form["changes"],
InConfig: r.Body,
OutStream: utils.NewWriteFlusher(w),
}
if version.GreaterThan("1.0") {
imageImportConfig.Json = true
w.Header().Set("Content-Type", "application/json")
} else {
imageImportConfig.Json = false
Json: useJSON,
}
newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
@ -789,9 +786,12 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
}
imageImportConfig.ContainerConfig = newConfig
if err := s.daemon.Repositories().Import(src, repo, tag, imageImportConfig); err != nil {
return err
}
opErr = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig)
}
if opErr != nil {
sf := streamformatter.NewStreamFormatter(useJSON)
return fmt.Errorf(string(sf.FormatError(opErr)))
}
return nil

View file

@ -98,8 +98,13 @@ func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
// pulling a non-existing image from the central registry should return a non-zero exit code
func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234")
if out, _, err := runCommandWithOutput(pullCmd); err == nil {
testRequires(c, Network)
name := "sadfsadfasdf"
pullCmd := exec.Command(dockerBinary, "pull", name)
out, _, err := runCommandWithOutput(pullCmd)
if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
}
}