Skip to content

Commit

Permalink
fix: errors returned by zot should match the dist-spec errors (#1868)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexei Dodon <[email protected]>
  • Loading branch information
adodon2go authored Sep 29, 2023
1 parent 56e3580 commit 75085dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
28 changes: 6 additions & 22 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ const (
MANIFEST_BLOB_UNKNOWN
MANIFEST_INVALID
MANIFEST_UNKNOWN
MANIFEST_UNVERIFIED
NAME_INVALID
NAME_UNKNOWN
SIZE_INVALID
TAG_INVALID
UNAUTHORIZED
DENIED
UNSUPPORTED
INVALID_INDEX
TOOMANYREQUESTS
)

func (e ErrorCode) String() string {
Expand All @@ -46,15 +44,13 @@ func (e ErrorCode) String() string {
MANIFEST_BLOB_UNKNOWN: "MANIFEST_BLOB_UNKNOWN",
MANIFEST_INVALID: "MANIFEST_INVALID",
MANIFEST_UNKNOWN: "MANIFEST_UNKNOWN",
MANIFEST_UNVERIFIED: "MANIFEST_UNVERIFIED",
NAME_INVALID: "NAME_INVALID",
NAME_UNKNOWN: "NAME_UNKNOWN",
SIZE_INVALID: "SIZE_INVALID",
TAG_INVALID: "TAG_INVALID",
UNAUTHORIZED: "UNAUTHORIZED",
DENIED: "DENIED",
UNSUPPORTED: "UNSUPPORTED",
INVALID_INDEX: "INVALID_INDEX",
TOOMANYREQUESTS: "TOOMANYREQUESTS",
}

return errMap[e]
Expand Down Expand Up @@ -105,12 +101,6 @@ func NewError(code ErrorCode) *Error {
"and tag is unknown to the repository.",
},

MANIFEST_UNVERIFIED: {
Message: "manifest failed signature verification",
Description: "During manifest upload, if the manifest fails signature " +
"verification, this error will be returned.",
},

NAME_INVALID: {
Message: "invalid repository name",
Description: "Invalid repository name encountered either during manifest " +
Expand All @@ -128,12 +118,6 @@ func NewError(code ErrorCode) *Error {
"the uploaded content. If they do not match, this error will be returned.",
},

TAG_INVALID: {
Message: "manifest tag did not match URI",
Description: "During a manifest upload, if the tag in the manifest does " +
"not match the uri tag, this error will be returned.",
},

UNAUTHORIZED: {
Message: "authentication required",
Description: "The access controller was unable to authenticate the client." +
Expand All @@ -147,14 +131,14 @@ func NewError(code ErrorCode) *Error {
},

UNSUPPORTED: {
Message: "The operation is unsupported.",
Message: "the operation is unsupported",
Description: "The operation was unsupported due to a missing " +
"implementation or invalid set of parameters.",
},

INVALID_INDEX: {
Message: "Invalid format of index.json file of the repo",
Description: "index.json file does not contain data in json format",
TOOMANYREQUESTS: {
Message: "too many requests",
Description: "When a user or users has sent too many requests to the server within a given amount of time.",
},
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,6 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
details["blob"] = digest.String()
e := apiErr.NewError(apiErr.BLOB_UNKNOWN).AddDetail(details)
zcommon.WriteJSON(response, http.StatusBadRequest, apiErr.NewErrorList(e))
} else if errors.Is(err, zerr.ErrRepoBadVersion) {
details["name"] = name
e := apiErr.NewError(apiErr.INVALID_INDEX).AddDetail(details)
zcommon.WriteJSON(response, http.StatusInternalServerError, apiErr.NewErrorList(e))
} else if errors.Is(err, zerr.ErrImageLintAnnotations) {
details["reference"] = reference
e := apiErr.NewError(apiErr.MANIFEST_INVALID).AddDetail(details)
Expand Down

0 comments on commit 75085dc

Please sign in to comment.