Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stringer for "enums" #2144

Merged
merged 9 commits into from
Mar 10, 2023
Prev Previous commit
Next Next commit
Make linter happy
  • Loading branch information
AlekSi committed Mar 10, 2023
commit 795d6808ffb1e76c01ad595fd7b5364886355a50
30 changes: 12 additions & 18 deletions internal/handlers/common/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,15 @@ func processRenameFieldExpression(doc *types.Document, update *types.Document) (
sourcePath, err := types.NewPathFromString(key)
if err != nil {
var pathErr *types.DocumentPathError

if errors.As(err, &pathErr) {
switch pathErr.Code() {
case types.ErrDocumentPathEmptyKey:
return false, commonerrors.NewWriteErrorMsg(
commonerrors.ErrEmptyName,
fmt.Sprintf("Cannot apply $rename to a value of non-numeric type. "+
"{_id: %s} has the field '%s' of non-numeric type object",
must.NotFail(doc.Get("_id")),
key,
),
)
}
if errors.As(err, &pathErr) && pathErr.Code() == types.ErrDocumentPathEmptyKey {
return false, commonerrors.NewWriteErrorMsg(
commonerrors.ErrEmptyName,
fmt.Sprintf("Cannot apply $rename to a value of non-numeric type. "+
"{_id: %s} has the field '%s' of non-numeric type object",
must.NotFail(doc.Get("_id")),
key,
),
)
}
}

Expand All @@ -289,13 +285,11 @@ func processRenameFieldExpression(doc *types.Document, update *types.Document) (
panic("getByPath returned error with invalid type")
}

switch dpe.Code() {
case types.ErrDocumentPathKeyNotFound,
types.ErrDocumentPathIndexOutOfBound:
if dpe.Code() == types.ErrDocumentPathKeyNotFound || dpe.Code() == types.ErrDocumentPathIndexOutOfBound {
continue
default:
return changed, commonerrors.NewWriteErrorMsg(commonerrors.ErrUnsuitableValueType, dpe.Error())
}

return changed, commonerrors.NewWriteErrorMsg(commonerrors.ErrUnsuitableValueType, dpe.Error())
}

// Remove old document
Expand Down