diff --git a/pkg/api/errors.go b/pkg/api/errors.go index ddd1c9f9..0ef63c7e 100644 --- a/pkg/api/errors.go +++ b/pkg/api/errors.go @@ -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"` } diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 37642d2e..dffef680 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -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") diff --git a/pkg/extensions/lint/lint.go b/pkg/extensions/lint/lint.go index d05c7893..118cf3e0 100644 --- a/pkg/extensions/lint/lint.go +++ b/pkg/extensions/lint/lint.go @@ -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 diff --git a/pkg/extensions/lint/lint_test.go b/pkg/extensions/lint/lint_test.go index 8e6b5d25..73fdbccf 100644 --- a/pkg/extensions/lint/lint_test.go +++ b/pkg/extensions/lint/lint_test.go @@ -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) })