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

Cleanup deprecated errors #2411

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions integration/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/FerretDB/FerretDB/integration/setup"
"github.com/FerretDB/FerretDB/integration/shareddata"
"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/handlers/commonerrors"
)

// TestDeleteSimple checks simple cases of doc deletion.
Expand Down Expand Up @@ -69,8 +69,8 @@ func TestDeleteLimitErrors(t *testing.T) {
"NotSet": {
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}}},
expectedErr: &mongo.CommandError{
Code: int32(common.ErrMissingField),
Name: common.ErrMissingField.String(),
Code: int32(commonerrors.ErrMissingField),
Name: commonerrors.ErrMissingField.String(),
Message: "BSON field 'delete.deletes.limit' is missing but a required field",
},
},
Expand All @@ -84,16 +84,16 @@ func TestDeleteLimitErrors(t *testing.T) {
"InvalidFloat": {
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", 42.13}}},
expectedErr: &mongo.CommandError{
Code: int32(common.ErrFailedToParse),
Name: common.ErrFailedToParse.String(),
Code: int32(commonerrors.ErrFailedToParse),
Name: commonerrors.ErrFailedToParse.String(),
Message: "The limit field in delete objects must be 0 or 1. Got 42.13",
},
},
"InvalidInt": {
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", 100}}},
expectedErr: &mongo.CommandError{
Code: int32(common.ErrFailedToParse),
Name: common.ErrFailedToParse.String(),
Code: int32(commonerrors.ErrFailedToParse),
Name: commonerrors.ErrFailedToParse.String(),
Message: "The limit field in delete objects must be 0 or 1. Got 100",
},
},
Expand Down
7 changes: 4 additions & 3 deletions internal/clientconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/FerretDB/FerretDB/internal/clientconn/connmetrics"
"github.com/FerretDB/FerretDB/internal/handlers"
"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/handlers/commonerrors"
"github.com/FerretDB/FerretDB/internal/handlers/proxy"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand Down Expand Up @@ -241,7 +242,7 @@ func (c *conn) run(ctx context.Context) (err error) {
var res wire.OpMsg

// get protocol error to return correct error document
protoErr, ok := common.ProtocolError(validationErr)
protoErr, ok := commonerrors.ProtocolError(validationErr)
if !ok {
panic(err)
}
Expand Down Expand Up @@ -439,7 +440,7 @@ func (c *conn) route(ctx context.Context, reqHeader *wire.MsgHeader, reqBody wir
if err != nil {
switch resHeader.OpCode {
case wire.OpCodeMsg:
protoErr, recoverable := common.ProtocolError(err)
protoErr, recoverable := commonerrors.ProtocolError(err)
closeConn = !recoverable

var res wire.OpMsg
Expand Down Expand Up @@ -523,7 +524,7 @@ func (c *conn) handleOpMsg(ctx context.Context, msg *wire.OpMsg, command string)

errMsg := fmt.Sprintf("no such command: '%s'", command)

return nil, common.NewCommandErrorMsg(common.ErrCommandNotFound, errMsg)
return nil, commonerrors.NewCommandErrorMsg(commonerrors.ErrCommandNotFound, errMsg)
}

// logResponse logs response's header and body and returns the log level that was used.
Expand Down
69 changes: 0 additions & 69 deletions internal/handlers/common/commonerrors.go

This file was deleted.

10 changes: 7 additions & 3 deletions internal/handlers/common/distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"go.uber.org/zap"

"github.com/FerretDB/FerretDB/internal/handlers/commonerrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
)
Expand Down Expand Up @@ -64,8 +65,8 @@ func GetDistinctParams(document *types.Document, l *zap.Logger) (*DistinctParams

var ok bool
if dp.Collection, ok = collectionParam.(string); !ok {
return nil, NewCommandErrorMsgWithArgument(
ErrInvalidNamespace,
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrInvalidNamespace,
fmt.Sprintf("collection name has invalid type %s", AliasFromType(collectionParam)),
document.Command(),
)
Expand All @@ -76,7 +77,10 @@ func GetDistinctParams(document *types.Document, l *zap.Logger) (*DistinctParams
}

if dp.Key == "" {
return nil, NewCommandErrorMsg(ErrEmptyFieldPath, "FieldPath cannot be constructed with empty string")
return nil, commonerrors.NewCommandErrorMsg(
commonerrors.ErrEmptyFieldPath,
"FieldPath cannot be constructed with empty string",
)
}

if dp.Filter, err = GetOptionalParam(document, "query", dp.Filter); err != nil {
Expand Down
Loading