Cleaned up error checking of 'docker push'

This commit is contained in:
Solomon Hykes 2013-03-25 17:20:55 -07:00
parent b31211cbe9
commit e4a69b1044
1 changed files with 10 additions and 21 deletions

View File

@ -231,25 +231,18 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth
req.Header.Add("Content-type", "application/json") req.Header.Add("Content-type", "application/json")
req.SetBasicAuth(authConfig.Username, authConfig.Password) req.SetBasicAuth(authConfig.Username, authConfig.Password)
res, err := client.Do(req) res, err := client.Do(req)
if err != nil || res.StatusCode != 200 { if err != nil {
if res == nil { return fmt.Errorf("Failed to upload json: %s", err)
return fmt.Errorf(
"Error: Internal server error trying to push image {%s} (json): %s",
img.Id, err)
} }
if res.StatusCode != 200 {
Debugf("Pushing return status: %d\n", res.StatusCode) Debugf("Pushing return status: %d\n", res.StatusCode)
switch res.StatusCode { switch res.StatusCode {
case 204: case 204:
// Case where the image is already on the Registry // Case where the image is already on the Registry
// FIXME: Do not be silent? // FIXME: Do not be silent?
fmt.Fprintf(stdout, "The image %s is already up to date on the registry.\n", img.Id)
return nil return nil
case 400:
return fmt.Errorf("Error: Invalid Json")
default: default:
return fmt.Errorf( return fmt.Errorf("Received HTTP code %d while uploading json", res.StatusCode)
"Error: Internal server error: %d trying to push image {%s} (json): %s\n",
res.StatusCode, img.Id, err)
} }
} }
@ -284,15 +277,11 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth
req3.TransferEncoding = []string{"none"} req3.TransferEncoding = []string{"none"}
res3, err := client.Do(req3) res3, err := client.Do(req3)
if err != nil || res3.StatusCode != 200 { if err != nil {
if res3 == nil { return fmt.Errorf("Failed to upload layer: %s", err)
return fmt.Errorf(
"Error trying to push image {%s} (layer 2): %s\n",
img.Id, err)
} }
return fmt.Errorf( if res3.StatusCode != 200 {
"Error trying to push image {%s} (layer 2): %s (%d)\n", return fmt.Errorf("Received HTTP code %d while uploading layer", res3.StatusCode)
img.Id, err, res3.StatusCode)
} }
return nil return nil
}); err != nil { }); err != nil {