0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

feat(routes): better error message in case of missing annotations (#1150)

putting this info into error detail would be ideal, but skopeo
doesn't print them, so overwrite the error message.

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu 2023-03-17 05:09:30 +02:00 committed by GitHub
parent eea6f3f85a
commit 17a554b504
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -11,6 +11,12 @@ type Error struct {
Detail interface{} `json:"detail,omitempty"`
}
func (e Error) WithMessage(msg string) Error {
e.Message = msg
return e
}
type ErrorList struct {
Errors []*Error `json:"errors"`
}

View file

@ -587,7 +587,7 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
NewErrorList(NewError(INVALID_INDEX, map[string]string{"name": name})))
} else if errors.Is(err, zerr.ErrImageLintAnnotations) {
WriteJSON(response, http.StatusBadRequest,
NewErrorList(NewError(MANIFEST_INVALID, map[string]string{"reference": reference})))
NewErrorList(NewError(MANIFEST_INVALID, map[string]string{"reference": reference}).WithMessage(err.Error())))
} else {
// could be syscall.EMFILE (Err:0x18 too many opened files), etc
rh.c.Log.Error().Err(err).Msg("unexpected error: performing cleanup")

View file

@ -5,10 +5,13 @@ package lint
import (
"encoding/json"
"fmt"
godigest "github.com/opencontainers/go-digest"
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
zerr "zotregistry.io/zot/errors"
"zotregistry.io/zot/pkg/extensions/config"
"zotregistry.io/zot/pkg/log"
"zotregistry.io/zot/pkg/storage"
@ -98,10 +101,11 @@ func (linter *Linter) CheckMandatoryAnnotations(repo string, manifestDigest godi
missingAnnotations = getMissingAnnotations(mandatoryAnnotationsMap)
if len(missingAnnotations) > 0 {
linter.log.Error().Msgf("linter: manifest %s / config %s are missing annotations: %s",
msg := fmt.Sprintf("\nlinter: manifest %s\nor config %s\nis missing the next annotations: %s",
string(manifestDigest), string(configDigest), missingAnnotations)
linter.log.Error().Msg(msg)
return false, nil
return false, errors.WithMessage(zerr.ErrImageLintAnnotations, msg)
}
return true, nil

View file

@ -636,7 +636,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
pass, err := linter.CheckMandatoryAnnotations("zot-test", digest, imgStore)
So(err, ShouldBeNil)
So(err, ShouldNotBeNil)
So(pass, ShouldBeFalse)
})