registry/api/errcode: split Register to internal / exported

Use the non-exported function to all errors; there's currently no external
consumers of this function (perhaps it should be deprecated).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-09-04 17:54:48 +02:00
parent 292e30bc61
commit 0104adf4a8
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 29 additions and 23 deletions

View file

@ -10,21 +10,21 @@ import (
// TestErrorsManagement does a quick check of the Errors type to ensure that // TestErrorsManagement does a quick check of the Errors type to ensure that
// members are properly pushed and marshaled. // members are properly pushed and marshaled.
var ErrorCodeTest1 = Register("test.errors", ErrorDescriptor{ var ErrorCodeTest1 = register("test.errors", ErrorDescriptor{
Value: "TEST1", Value: "TEST1",
Message: "test error 1", Message: "test error 1",
Description: `Just a test message #1.`, Description: `Just a test message #1.`,
HTTPStatusCode: http.StatusInternalServerError, HTTPStatusCode: http.StatusInternalServerError,
}) })
var ErrorCodeTest2 = Register("test.errors", ErrorDescriptor{ var ErrorCodeTest2 = register("test.errors", ErrorDescriptor{
Value: "TEST2", Value: "TEST2",
Message: "test error 2", Message: "test error 2",
Description: `Just a test message #2.`, Description: `Just a test message #2.`,
HTTPStatusCode: http.StatusNotFound, HTTPStatusCode: http.StatusNotFound,
}) })
var ErrorCodeTest3 = Register("test.errors", ErrorDescriptor{ var ErrorCodeTest3 = register("test.errors", ErrorDescriptor{
Value: "TEST3", Value: "TEST3",
Message: "Sorry %q isn't valid", Message: "Sorry %q isn't valid",
Description: `Just a test message #3.`, Description: `Just a test message #3.`,

View file

@ -16,7 +16,7 @@ var (
var ( var (
// ErrorCodeUnknown is a generic error that can be used as a last // ErrorCodeUnknown is a generic error that can be used as a last
// resort if there is no situation-specific error message that can be used // resort if there is no situation-specific error message that can be used
ErrorCodeUnknown = Register("errcode", ErrorDescriptor{ ErrorCodeUnknown = register("errcode", ErrorDescriptor{
Value: "UNKNOWN", Value: "UNKNOWN",
Message: "unknown error", Message: "unknown error",
Description: `Generic error returned when the error does not have an Description: `Generic error returned when the error does not have an
@ -25,7 +25,7 @@ var (
}) })
// ErrorCodeUnsupported is returned when an operation is not supported. // ErrorCodeUnsupported is returned when an operation is not supported.
ErrorCodeUnsupported = Register("errcode", ErrorDescriptor{ ErrorCodeUnsupported = register("errcode", ErrorDescriptor{
Value: "UNSUPPORTED", Value: "UNSUPPORTED",
Message: "The operation is unsupported.", Message: "The operation is unsupported.",
Description: `The operation was unsupported due to a missing Description: `The operation was unsupported due to a missing
@ -35,7 +35,7 @@ var (
// ErrorCodeUnauthorized is returned if a request requires // ErrorCodeUnauthorized is returned if a request requires
// authentication. // authentication.
ErrorCodeUnauthorized = Register("errcode", ErrorDescriptor{ ErrorCodeUnauthorized = register("errcode", ErrorDescriptor{
Value: "UNAUTHORIZED", Value: "UNAUTHORIZED",
Message: "authentication required", Message: "authentication required",
Description: `The access controller was unable to authenticate Description: `The access controller was unable to authenticate
@ -47,7 +47,7 @@ var (
// ErrorCodeDenied is returned if a client does not have sufficient // ErrorCodeDenied is returned if a client does not have sufficient
// permission to perform an action. // permission to perform an action.
ErrorCodeDenied = Register("errcode", ErrorDescriptor{ ErrorCodeDenied = register("errcode", ErrorDescriptor{
Value: "DENIED", Value: "DENIED",
Message: "requested access to the resource is denied", Message: "requested access to the resource is denied",
Description: `The access controller denied access for the Description: `The access controller denied access for the
@ -57,7 +57,7 @@ var (
// ErrorCodeUnavailable provides a common error to report unavailability // ErrorCodeUnavailable provides a common error to report unavailability
// of a service or endpoint. // of a service or endpoint.
ErrorCodeUnavailable = Register("errcode", ErrorDescriptor{ ErrorCodeUnavailable = register("errcode", ErrorDescriptor{
Value: "UNAVAILABLE", Value: "UNAVAILABLE",
Message: "service unavailable", Message: "service unavailable",
Description: "Returned when a service is not available", Description: "Returned when a service is not available",
@ -66,7 +66,7 @@ var (
// ErrorCodeTooManyRequests is returned if a client attempts too many // ErrorCodeTooManyRequests is returned if a client attempts too many
// times to contact a service endpoint. // times to contact a service endpoint.
ErrorCodeTooManyRequests = Register("errcode", ErrorDescriptor{ ErrorCodeTooManyRequests = register("errcode", ErrorDescriptor{
Value: "TOOMANYREQUESTS", Value: "TOOMANYREQUESTS",
Message: "too many requests", Message: "too many requests",
Description: `Returned when a client attempts to contact a Description: `Returned when a client attempts to contact a
@ -80,7 +80,7 @@ const errGroup = "registry.api.v2"
var ( var (
// ErrorCodeDigestInvalid is returned when uploading a blob if the // ErrorCodeDigestInvalid is returned when uploading a blob if the
// provided digest does not match the blob contents. // provided digest does not match the blob contents.
ErrorCodeDigestInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeDigestInvalid = register(errGroup, ErrorDescriptor{
Value: "DIGEST_INVALID", Value: "DIGEST_INVALID",
Message: "provided digest did not match uploaded content", Message: "provided digest did not match uploaded content",
Description: `When a blob is uploaded, the registry will check that Description: `When a blob is uploaded, the registry will check that
@ -92,7 +92,7 @@ var (
}) })
// ErrorCodeSizeInvalid is returned when uploading a blob if the provided // ErrorCodeSizeInvalid is returned when uploading a blob if the provided
ErrorCodeSizeInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeSizeInvalid = register(errGroup, ErrorDescriptor{
Value: "SIZE_INVALID", Value: "SIZE_INVALID",
Message: "provided length did not match content length", Message: "provided length did not match content length",
Description: `When a layer is uploaded, the provided size will be Description: `When a layer is uploaded, the provided size will be
@ -103,7 +103,7 @@ var (
// ErrorCodeRangeInvalid is returned when uploading a blob if the provided // ErrorCodeRangeInvalid is returned when uploading a blob if the provided
// content range is invalid. // content range is invalid.
ErrorCodeRangeInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeRangeInvalid = register(errGroup, ErrorDescriptor{
Value: "RANGE_INVALID", Value: "RANGE_INVALID",
Message: "invalid content range", Message: "invalid content range",
Description: `When a layer is uploaded, the provided range is checked Description: `When a layer is uploaded, the provided range is checked
@ -114,7 +114,7 @@ var (
// ErrorCodeNameInvalid is returned when the name in the manifest does not // ErrorCodeNameInvalid is returned when the name in the manifest does not
// match the provided name. // match the provided name.
ErrorCodeNameInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeNameInvalid = register(errGroup, ErrorDescriptor{
Value: "NAME_INVALID", Value: "NAME_INVALID",
Message: "invalid repository name", Message: "invalid repository name",
Description: `Invalid repository name encountered either during Description: `Invalid repository name encountered either during
@ -124,7 +124,7 @@ var (
// ErrorCodeTagInvalid is returned when the tag in the manifest does not // ErrorCodeTagInvalid is returned when the tag in the manifest does not
// match the provided tag. // match the provided tag.
ErrorCodeTagInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeTagInvalid = register(errGroup, ErrorDescriptor{
Value: "TAG_INVALID", Value: "TAG_INVALID",
Message: "manifest tag did not match URI", Message: "manifest tag did not match URI",
Description: `During a manifest upload, if the tag in the manifest Description: `During a manifest upload, if the tag in the manifest
@ -133,7 +133,7 @@ var (
}) })
// ErrorCodeNameUnknown when the repository name is not known. // ErrorCodeNameUnknown when the repository name is not known.
ErrorCodeNameUnknown = Register(errGroup, ErrorDescriptor{ ErrorCodeNameUnknown = register(errGroup, ErrorDescriptor{
Value: "NAME_UNKNOWN", Value: "NAME_UNKNOWN",
Message: "repository name not known to registry", Message: "repository name not known to registry",
Description: `This is returned if the name used during an operation is Description: `This is returned if the name used during an operation is
@ -142,7 +142,7 @@ var (
}) })
// ErrorCodeManifestUnknown returned when image manifest is unknown. // ErrorCodeManifestUnknown returned when image manifest is unknown.
ErrorCodeManifestUnknown = Register(errGroup, ErrorDescriptor{ ErrorCodeManifestUnknown = register(errGroup, ErrorDescriptor{
Value: "MANIFEST_UNKNOWN", Value: "MANIFEST_UNKNOWN",
Message: "manifest unknown", Message: "manifest unknown",
Description: `This error is returned when the manifest, identified by Description: `This error is returned when the manifest, identified by
@ -153,7 +153,7 @@ var (
// ErrorCodeManifestInvalid returned when an image manifest is invalid, // ErrorCodeManifestInvalid returned when an image manifest is invalid,
// typically during a PUT operation. This error encompasses all errors // typically during a PUT operation. This error encompasses all errors
// encountered during manifest validation that aren't signature errors. // encountered during manifest validation that aren't signature errors.
ErrorCodeManifestInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeManifestInvalid = register(errGroup, ErrorDescriptor{
Value: "MANIFEST_INVALID", Value: "MANIFEST_INVALID",
Message: "manifest invalid", Message: "manifest invalid",
Description: `During upload, manifests undergo several checks ensuring Description: `During upload, manifests undergo several checks ensuring
@ -165,7 +165,7 @@ var (
// ErrorCodeManifestUnverified is returned when the manifest fails // ErrorCodeManifestUnverified is returned when the manifest fails
// signature verification. // signature verification.
ErrorCodeManifestUnverified = Register(errGroup, ErrorDescriptor{ ErrorCodeManifestUnverified = register(errGroup, ErrorDescriptor{
Value: "MANIFEST_UNVERIFIED", Value: "MANIFEST_UNVERIFIED",
Message: "manifest failed signature verification", Message: "manifest failed signature verification",
Description: `During manifest upload, if the manifest fails signature Description: `During manifest upload, if the manifest fails signature
@ -175,7 +175,7 @@ var (
// ErrorCodeManifestBlobUnknown is returned when a manifest blob is // ErrorCodeManifestBlobUnknown is returned when a manifest blob is
// unknown to the registry. // unknown to the registry.
ErrorCodeManifestBlobUnknown = Register(errGroup, ErrorDescriptor{ ErrorCodeManifestBlobUnknown = register(errGroup, ErrorDescriptor{
Value: "MANIFEST_BLOB_UNKNOWN", Value: "MANIFEST_BLOB_UNKNOWN",
Message: "blob unknown to registry", Message: "blob unknown to registry",
Description: `This error may be returned when a manifest blob is Description: `This error may be returned when a manifest blob is
@ -186,7 +186,7 @@ var (
// ErrorCodeBlobUnknown is returned when a blob is unknown to the // ErrorCodeBlobUnknown is returned when a blob is unknown to the
// registry. This can happen when the manifest references a nonexistent // registry. This can happen when the manifest references a nonexistent
// layer or the result is not found by a blob fetch. // layer or the result is not found by a blob fetch.
ErrorCodeBlobUnknown = Register(errGroup, ErrorDescriptor{ ErrorCodeBlobUnknown = register(errGroup, ErrorDescriptor{
Value: "BLOB_UNKNOWN", Value: "BLOB_UNKNOWN",
Message: "blob unknown to registry", Message: "blob unknown to registry",
Description: `This error may be returned when a blob is unknown to the Description: `This error may be returned when a blob is unknown to the
@ -197,7 +197,7 @@ var (
}) })
// ErrorCodeBlobUploadUnknown is returned when an upload is unknown. // ErrorCodeBlobUploadUnknown is returned when an upload is unknown.
ErrorCodeBlobUploadUnknown = Register(errGroup, ErrorDescriptor{ ErrorCodeBlobUploadUnknown = register(errGroup, ErrorDescriptor{
Value: "BLOB_UPLOAD_UNKNOWN", Value: "BLOB_UPLOAD_UNKNOWN",
Message: "blob upload unknown to registry", Message: "blob upload unknown to registry",
Description: `If a blob upload has been cancelled or was never Description: `If a blob upload has been cancelled or was never
@ -206,7 +206,7 @@ var (
}) })
// ErrorCodeBlobUploadInvalid is returned when an upload is invalid. // ErrorCodeBlobUploadInvalid is returned when an upload is invalid.
ErrorCodeBlobUploadInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodeBlobUploadInvalid = register(errGroup, ErrorDescriptor{
Value: "BLOB_UPLOAD_INVALID", Value: "BLOB_UPLOAD_INVALID",
Message: "blob upload invalid", Message: "blob upload invalid",
Description: `The blob upload encountered an error and can no Description: `The blob upload encountered an error and can no
@ -216,7 +216,7 @@ var (
// ErrorCodePaginationNumberInvalid is returned when the `n` parameter is // ErrorCodePaginationNumberInvalid is returned when the `n` parameter is
// not an integer, or `n` is negative. // not an integer, or `n` is negative.
ErrorCodePaginationNumberInvalid = Register(errGroup, ErrorDescriptor{ ErrorCodePaginationNumberInvalid = register(errGroup, ErrorDescriptor{
Value: "PAGINATION_NUMBER_INVALID", Value: "PAGINATION_NUMBER_INVALID",
Message: "invalid number of results requested", Message: "invalid number of results requested",
Description: `Returned when the "n" parameter (number of results Description: `Returned when the "n" parameter (number of results
@ -234,6 +234,12 @@ var (
// Register will make the passed-in error known to the environment and // Register will make the passed-in error known to the environment and
// return a new ErrorCode // return a new ErrorCode
func Register(group string, descriptor ErrorDescriptor) ErrorCode { func Register(group string, descriptor ErrorDescriptor) ErrorCode {
return register(group, descriptor)
}
// register will make the passed-in error known to the environment and
// return a new ErrorCode
func register(group string, descriptor ErrorDescriptor) ErrorCode {
registerLock.Lock() registerLock.Lock()
defer registerLock.Unlock() defer registerLock.Unlock()