Skip to content

Commit

Permalink
Handle no path for delete objects in gateway (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiad200 authored Apr 4, 2021
1 parent 6a01ee3 commit e764bb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/catalog/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/gateway/operations/deleteobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.
lg.Debug("tried to delete with an empty branch")
case err != nil:
lg.WithError(err).Error("failed deleting object")
errs = append(errs, serde.DeleteError{
Expand Down

0 comments on commit e764bb8

Please sign in to comment.