2023-06-22 06:29:45 -05:00
|
|
|
package errors
|
2019-06-20 18:36:40 -05:00
|
|
|
|
2020-01-31 02:54:05 -05:00
|
|
|
import (
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/errors"
|
2020-01-31 02:54:05 -05:00
|
|
|
)
|
2019-06-20 18:36:40 -05:00
|
|
|
|
|
|
|
type Error struct {
|
2023-08-23 12:59:52 -05:00
|
|
|
Code string `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Description string `json:"-"`
|
|
|
|
Detail map[string]string `json:"detail"`
|
2023-03-16 22:09:30 -05:00
|
|
|
}
|
|
|
|
|
2019-06-20 18:36:40 -05:00
|
|
|
type ErrorList struct {
|
|
|
|
Errors []*Error `json:"errors"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorCode int
|
|
|
|
|
2022-10-05 05:21:14 -05:00
|
|
|
//nolint:golint,stylecheck,revive
|
2019-06-20 18:36:40 -05:00
|
|
|
const (
|
|
|
|
BLOB_UNKNOWN ErrorCode = iota
|
|
|
|
BLOB_UPLOAD_INVALID
|
|
|
|
BLOB_UPLOAD_UNKNOWN
|
|
|
|
DIGEST_INVALID
|
|
|
|
MANIFEST_BLOB_UNKNOWN
|
|
|
|
MANIFEST_INVALID
|
|
|
|
MANIFEST_UNKNOWN
|
|
|
|
MANIFEST_UNVERIFIED
|
|
|
|
NAME_INVALID
|
|
|
|
NAME_UNKNOWN
|
|
|
|
SIZE_INVALID
|
|
|
|
TAG_INVALID
|
|
|
|
UNAUTHORIZED
|
|
|
|
DENIED
|
|
|
|
UNSUPPORTED
|
2022-01-23 15:26:02 -05:00
|
|
|
INVALID_INDEX
|
2019-06-20 18:36:40 -05:00
|
|
|
)
|
|
|
|
|
2020-01-31 02:54:05 -05:00
|
|
|
func (e ErrorCode) String() string {
|
2021-12-13 14:23:31 -05:00
|
|
|
errMap := map[ErrorCode]string{
|
2020-01-31 02:54:05 -05:00
|
|
|
BLOB_UNKNOWN: "BLOB_UNKNOWN",
|
|
|
|
BLOB_UPLOAD_INVALID: "BLOB_UPLOAD_INVALID",
|
|
|
|
BLOB_UPLOAD_UNKNOWN: "BLOB_UPLOAD_UNKNOWN",
|
|
|
|
DIGEST_INVALID: "DIGEST_INVALID",
|
|
|
|
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",
|
2022-01-23 15:26:02 -05:00
|
|
|
INVALID_INDEX: "INVALID_INDEX",
|
2020-01-31 02:54:05 -05:00
|
|
|
}
|
2020-01-31 02:59:36 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
return errMap[e]
|
2020-01-31 02:54:05 -05:00
|
|
|
}
|
|
|
|
|
2023-08-23 12:59:52 -05:00
|
|
|
func NewError(code ErrorCode) *Error {
|
2021-12-13 14:23:31 -05:00
|
|
|
errMap := map[ErrorCode]Error{
|
2019-06-20 18:36:40 -05:00
|
|
|
BLOB_UNKNOWN: {
|
|
|
|
Message: "blob unknown to registry",
|
|
|
|
Description: "blob unknown to registry This error MAY be returned when a blob is unknown " +
|
|
|
|
" to the registry in a specified repository. This can be returned with a standard get or " +
|
|
|
|
"if a manifest references an unknown layer during upload.",
|
|
|
|
},
|
|
|
|
|
|
|
|
BLOB_UPLOAD_INVALID: {
|
|
|
|
Message: "blob upload invalid",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "The blob upload encountered an error and can no longer proceed.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
BLOB_UPLOAD_UNKNOWN: {
|
|
|
|
Message: "blob upload unknown to registry",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "If a blob upload has been cancelled or was never started, this error code MAY be returned.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
DIGEST_INVALID: {
|
|
|
|
Message: "provided digest did not match uploaded content",
|
|
|
|
Description: "When a blob is uploaded, the registry will check that the content matches the " +
|
|
|
|
"digest provided by the client. The error MAY include a detail structure with the key " +
|
|
|
|
"\"digest\", including the invalid digest string. This error MAY also be returned when " +
|
|
|
|
"a manifest includes an invalid layer digest.",
|
|
|
|
},
|
|
|
|
|
|
|
|
MANIFEST_BLOB_UNKNOWN: {
|
2023-08-23 12:59:52 -05:00
|
|
|
Message: "blob unknown to registry",
|
|
|
|
Description: "This error MAY be returned when a manifest blob is unknown to the registry.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
MANIFEST_INVALID: {
|
|
|
|
Message: "manifest invalid",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "During upload, manifests undergo several checks ensuring " +
|
|
|
|
"validity. If those checks fail, this error MAY be returned, unless a more " +
|
|
|
|
"specific error is included. The detail will contain information the failed validation.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
MANIFEST_UNKNOWN: {
|
|
|
|
Message: "manifest unknown",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "This error is returned when the manifest, identified by name " +
|
|
|
|
"and tag is unknown to the repository.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
MANIFEST_UNVERIFIED: {
|
|
|
|
Message: "manifest failed signature verification",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "During manifest upload, if the manifest fails signature " +
|
|
|
|
"verification, this error will be returned.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
NAME_INVALID: {
|
|
|
|
Message: "invalid repository name",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "Invalid repository name encountered either during manifest " +
|
|
|
|
"validation or any API operation.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
NAME_UNKNOWN: {
|
|
|
|
Message: "repository name not known to registry",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "This is returned if the name used during an operation is unknown to the registry.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
SIZE_INVALID: {
|
|
|
|
Message: "provided length did not match content length",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "When a layer is uploaded, the provided size will be checked against " +
|
|
|
|
"the uploaded content. If they do not match, this error will be returned.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
TAG_INVALID: {
|
|
|
|
Message: "manifest tag did not match URI",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "During a manifest upload, if the tag in the manifest does " +
|
|
|
|
"not match the uri tag, this error will be returned.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
UNAUTHORIZED: {
|
|
|
|
Message: "authentication required",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "The access controller was unable to authenticate the client." +
|
|
|
|
"Often this will be accompanied by a Www-Authenticate HTTP response header " +
|
|
|
|
"indicating how to authenticate.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
DENIED: {
|
2023-08-23 12:59:52 -05:00
|
|
|
Message: "requested access to the resource is denied",
|
|
|
|
Description: "The access controller denied access for the operation on a resource.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
UNSUPPORTED: {
|
|
|
|
Message: "The operation is unsupported.",
|
2023-08-23 12:59:52 -05:00
|
|
|
Description: "The operation was unsupported due to a missing " +
|
|
|
|
"implementation or invalid set of parameters.",
|
2019-06-20 18:36:40 -05:00
|
|
|
},
|
2022-01-23 15:26:02 -05:00
|
|
|
|
|
|
|
INVALID_INDEX: {
|
|
|
|
Message: "Invalid format of index.json file of the repo",
|
|
|
|
Description: "index.json file does not contain data in json format",
|
|
|
|
},
|
2019-06-20 18:36:40 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err, ok := errMap[code]
|
2019-06-20 18:36:40 -05:00
|
|
|
if !ok {
|
|
|
|
panic(errors.ErrUnknownCode)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err.Code = code.String()
|
2023-08-23 12:59:52 -05:00
|
|
|
err.Detail = map[string]string{
|
|
|
|
"description": err.Description,
|
|
|
|
}
|
2019-12-13 00:53:18 -05:00
|
|
|
|
2023-08-23 12:59:52 -05:00
|
|
|
return &err
|
2019-06-20 18:36:40 -05:00
|
|
|
}
|
2020-01-31 02:54:05 -05:00
|
|
|
|
2023-08-23 12:59:52 -05:00
|
|
|
func (err *Error) AddDetail(m map[string]string) *Error {
|
|
|
|
for k, v := range m {
|
|
|
|
err.Detail[k] = v
|
2020-01-31 02:54:05 -05:00
|
|
|
}
|
|
|
|
|
2023-08-23 12:59:52 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewErrorList(errors ...*Error) ErrorList {
|
|
|
|
var errList []*Error
|
|
|
|
errList = append(errList, errors...)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
return ErrorList{errList}
|
2020-01-31 02:54:05 -05:00
|
|
|
}
|