From ee07c09cfa27a89458dbee6ff63ef6b1f7b1bd89 Mon Sep 17 00:00:00 2001 From: Itai Admi Date: Sun, 4 Apr 2021 14:06:21 +0300 Subject: [PATCH 1/2] Handle no path for delete objects in gateway --- pkg/gateway/operations/deleteobjects.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/gateway/operations/deleteobjects.go b/pkg/gateway/operations/deleteobjects.go index a0016a78dc2..62087eddd82 100644 --- a/pkg/gateway/operations/deleteobjects.go +++ b/pkg/gateway/operations/deleteobjects.go @@ -63,6 +63,11 @@ func (controller *DeleteObjects) Handle(w http.ResponseWriter, req *http.Request switch { case errors.Is(err, catalog.ErrNotFound): lg.Debug("tried to delete a non-existent object") + case errors.Is(err, catalog.ErrRequiredValue) && resolvedPath.Path == "": + // issue #1706 - https://github.com/treeverse/lakeFS/issues/1706 + // Spark trying to delete the path "main/", which we map to branch "main" with an empty path. + // Spark expects it to succeed (not deleting anything is a success), instead of returning an error. + lg.Debug("tried to delete with an empty branch") case err != nil: lg.WithError(err).Error("failed deleting object") errs = append(errs, serde.DeleteError{ From c56ed018a7b9e0fc5a60dfca6233471b7164ae9f Mon Sep 17 00:00:00 2001 From: Itai Admi Date: Sun, 4 Apr 2021 14:45:17 +0300 Subject: [PATCH 2/2] Use special error value for missing path --- pkg/catalog/validate.go | 7 ++++--- pkg/gateway/operations/deleteobjects.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/catalog/validate.go b/pkg/catalog/validate.go index 326d1a45826..dbaa5286d06 100644 --- a/pkg/catalog/validate.go +++ b/pkg/catalog/validate.go @@ -21,8 +21,9 @@ var ( ) var ( - ErrInvalidType = errors.New("invalid type") - ErrRequiredValue = errors.New("required value") + ErrInvalidType = errors.New("invalid type") + ErrRequiredValue = errors.New("required value") + ErrPathRequiredValue = fmt.Errorf("missing path: %w", ErrRequiredValue) ) type ValidateFunc func(v interface{}) error @@ -171,7 +172,7 @@ func ValidatePath(v interface{}) error { } l := len(s.String()) if l == 0 { - return ErrRequiredValue + return ErrPathRequiredValue } if l > MaxPathLength { return fmt.Errorf("%w: %d is above maximum length (%d)", ErrInvalidValue, l, MaxPathLength) diff --git a/pkg/gateway/operations/deleteobjects.go b/pkg/gateway/operations/deleteobjects.go index 62087eddd82..ed0d8cd30be 100644 --- a/pkg/gateway/operations/deleteobjects.go +++ b/pkg/gateway/operations/deleteobjects.go @@ -63,7 +63,7 @@ func (controller *DeleteObjects) Handle(w http.ResponseWriter, req *http.Request switch { case errors.Is(err, catalog.ErrNotFound): lg.Debug("tried to delete a non-existent object") - case errors.Is(err, catalog.ErrRequiredValue) && resolvedPath.Path == "": + case errors.Is(err, catalog.ErrPathRequiredValue): // issue #1706 - https://github.com/treeverse/lakeFS/issues/1706 // Spark trying to delete the path "main/", which we map to branch "main" with an empty path. // Spark expects it to succeed (not deleting anything is a success), instead of returning an error.