Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit da0ca83

Browse files
committed
Adding error codes to image package
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
1 parent 9dc0973 commit da0ca83

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

errors/image.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package errors
2+
3+
// This file contains all of the errors that can be generated from the
4+
// docker/image component.
5+
6+
import (
7+
"net/http"
8+
9+
"github.com/docker/distribution/registry/api/errcode"
10+
)
11+
12+
var (
13+
// ErrorCodeInvalidImageID is generated when image id specified is incorrectly formatted.
14+
ErrorCodeInvalidImageID = errcode.Register(errGroup, errcode.ErrorDescriptor{
15+
Value: "INVALIDIMAGEID",
16+
Message: "image ID '%s' is invalid ",
17+
Description: "The specified image id is incorrectly formatted",
18+
HTTPStatusCode: http.StatusInternalServerError,
19+
})
20+
)

image/image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package image
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"regexp"
76
"time"
87

8+
derr "github.com/docker/docker/errors"
99
"github.com/docker/docker/runconfig"
1010
)
1111

@@ -53,7 +53,7 @@ func NewImgJSON(src []byte) (*Image, error) {
5353
// ValidateID checks whether an ID string is a valid image ID.
5454
func ValidateID(id string) error {
5555
if ok := validHex.MatchString(id); !ok {
56-
return fmt.Errorf("image ID '%s' is invalid", id)
56+
return derr.ErrorCodeInvalidImageID.WithArgs(id)
5757
}
5858
return nil
5959
}

0 commit comments

Comments
 (0)