| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+package errors |
|
| 1 |
+ |
|
| 2 |
+// This file contains all of the errors that can be generated from the |
|
| 3 |
+// docker/image component. |
|
| 4 |
+ |
|
| 5 |
+import ( |
|
| 6 |
+ "net/http" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/docker/distribution/registry/api/errcode" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+var ( |
|
| 12 |
+ // ErrorCodeInvalidImageID is generated when image id specified is incorrectly formatted. |
|
| 13 |
+ ErrorCodeInvalidImageID = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 14 |
+ Value: "INVALIDIMAGEID", |
|
| 15 |
+ Message: "image ID '%s' is invalid ", |
|
| 16 |
+ Description: "The specified image id is incorrectly formatted", |
|
| 17 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 18 |
+ }) |
|
| 19 |
+) |
| ... | ... |
@@ -2,10 +2,10 @@ package image |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"regexp" |
| 7 | 6 |
"time" |
| 8 | 7 |
|
| 8 |
+ derr "github.com/docker/docker/errors" |
|
| 9 | 9 |
"github.com/docker/docker/runconfig" |
| 10 | 10 |
) |
| 11 | 11 |
|
| ... | ... |
@@ -53,7 +53,7 @@ func NewImgJSON(src []byte) (*Image, error) {
|
| 53 | 53 |
// ValidateID checks whether an ID string is a valid image ID. |
| 54 | 54 |
func ValidateID(id string) error {
|
| 55 | 55 |
if ok := validHex.MatchString(id); !ok {
|
| 56 |
- return fmt.Errorf("image ID '%s' is invalid", id)
|
|
| 56 |
+ return derr.ErrorCodeInvalidImageID.WithArgs(id) |
|
| 57 | 57 |
} |
| 58 | 58 |
return nil |
| 59 | 59 |
} |