mirror of https://github.com/harness/drone.git
[maint] in when tree entry is not found return PathNotFound error (#921)
parent
ee7b2775c1
commit
98a18210a1
|
@ -25,6 +25,7 @@ import (
|
|||
events "github.com/harness/gitness/app/events/pullreq"
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git"
|
||||
gittypes "github.com/harness/gitness/git/types"
|
||||
"github.com/harness/gitness/store"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -343,7 +344,7 @@ func (c *Controller) fetchDiffCut(
|
|||
LineEnd: in.LineEnd,
|
||||
LineEndNew: in.LineEndNew,
|
||||
})
|
||||
if errors.AsStatus(err) == errors.StatusNotFound || errors.AsStatus(err) == errors.StatusPathNotFound {
|
||||
if errors.AsStatus(err) == errors.StatusNotFound || gittypes.IsPathNotFoundError(err) {
|
||||
return git.DiffCutOutput{}, usererror.BadRequest(errors.Message(err))
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -21,8 +21,8 @@ import (
|
|||
|
||||
"github.com/harness/gitness/app/api/usererror"
|
||||
"github.com/harness/gitness/app/auth"
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git"
|
||||
gittypes "github.com/harness/gitness/git/types"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
)
|
||||
|
@ -80,7 +80,7 @@ func (c *Controller) FileViewAdd(
|
|||
Path: in.Path,
|
||||
IncludeLatestCommit: false,
|
||||
})
|
||||
if err != nil && errors.AsStatus(err) != errors.StatusPathNotFound {
|
||||
if err != nil && !gittypes.IsPathNotFoundError(err) {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to get tree node '%s' for provided sha '%s': %w",
|
||||
in.Path,
|
||||
|
@ -102,7 +102,7 @@ func (c *Controller) FileViewAdd(
|
|||
Path: in.Path,
|
||||
IncludeLatestCommit: false,
|
||||
})
|
||||
if err != nil && errors.AsStatus(err) != errors.StatusPathNotFound {
|
||||
if err != nil && !gittypes.IsPathNotFoundError(err) {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to get tree node '%s' for MergeBaseSHA '%s': %w",
|
||||
in.Path,
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/harness/gitness/app/services/webhook"
|
||||
"github.com/harness/gitness/blob"
|
||||
"github.com/harness/gitness/errors"
|
||||
gittypes "github.com/harness/gitness/git/types"
|
||||
"github.com/harness/gitness/lock"
|
||||
"github.com/harness/gitness/store"
|
||||
"github.com/harness/gitness/types/check"
|
||||
|
@ -79,6 +80,11 @@ func Translate(err error) *Error {
|
|||
return RequestTooLargef("The request is too large. maximum allowed size is %d bytes", maxBytesErr.Limit)
|
||||
|
||||
// git errors
|
||||
case errors.Is(err, &gittypes.PathNotFoundError{}):
|
||||
return &Error{
|
||||
Status: http.StatusNotFound,
|
||||
Message: err.Error(),
|
||||
}
|
||||
case errors.As(err, &appError):
|
||||
return NewWithPayload(httpStatusCode(
|
||||
appError.Status),
|
||||
|
@ -124,7 +130,6 @@ var codes = map[errors.Status]int{
|
|||
errors.StatusConflict: http.StatusConflict,
|
||||
errors.StatusInvalidArgument: http.StatusBadRequest,
|
||||
errors.StatusNotFound: http.StatusNotFound,
|
||||
errors.StatusPathNotFound: http.StatusNotFound,
|
||||
errors.StatusNotImplemented: http.StatusNotImplemented,
|
||||
errors.StatusPreconditionFailed: http.StatusPreconditionFailed,
|
||||
errors.StatusUnauthorized: http.StatusUnauthorized,
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git"
|
||||
gittypes "github.com/harness/gitness/git/types"
|
||||
gitness_store "github.com/harness/gitness/store"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -255,7 +256,7 @@ func (s *Service) getCodeOwnerFileNode(
|
|||
Path: path,
|
||||
})
|
||||
|
||||
if errors.AsStatus(err) == errors.StatusPathNotFound {
|
||||
if gittypes.IsPathNotFoundError(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -26,7 +26,6 @@ const (
|
|||
StatusInternal Status = "internal"
|
||||
StatusInvalidArgument Status = "invalid"
|
||||
StatusNotFound Status = "not_found"
|
||||
StatusPathNotFound Status = "path_not_found"
|
||||
StatusNotImplemented Status = "not_implemented"
|
||||
StatusUnauthorized Status = "unauthorized"
|
||||
StatusFailed Status = "failed"
|
||||
|
|
|
@ -87,7 +87,7 @@ func lsTree(
|
|||
}
|
||||
|
||||
if output == "" {
|
||||
return nil, errors.Format(errors.StatusPathNotFound, "path %q not found", treePath)
|
||||
return nil, &types.PathNotFoundError{Path: treePath}
|
||||
}
|
||||
|
||||
n := strings.Count(output, "\x00")
|
||||
|
|
|
@ -26,13 +26,11 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrAlreadyExists = errors.New("already exists")
|
||||
ErrRepositoryNotFound = errors.New("repository not found")
|
||||
ErrRepositoryCorrupted = errors.New("repository corrupted")
|
||||
ErrInvalidPath = errors.New("path is invalid")
|
||||
ErrSHADoesNotMatch = errors.New("sha does not match")
|
||||
ErrNoDefaultBranch = errors.New("no default branch")
|
||||
ErrHunkNotFound = errors.New("hunk not found")
|
||||
ErrAlreadyExists = errors.New("already exists")
|
||||
ErrInvalidPath = errors.New("path is invalid")
|
||||
ErrSHADoesNotMatch = errors.New("sha does not match")
|
||||
ErrNoDefaultBranch = errors.New("no default branch")
|
||||
ErrHunkNotFound = errors.New("hunk not found")
|
||||
)
|
||||
|
||||
type NotFoundError struct {
|
||||
|
|
Loading…
Reference in New Issue