Skip to content

Commit

Permalink
Merge branch 'main' into proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Nov 30, 2023
2 parents 5881ea3 + 90ca808 commit eaaceea
Show file tree
Hide file tree
Showing 84 changed files with 1,028 additions and 1,024 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ linters-settings:
- "**/internal/backends/**/*.go"
deny:
- pkg: github.com/FerretDB/FerretDB/internal/handler/common
commonerrors:
handlererrors:
files:
- $all
- "!**/internal/clientconn/*.go"
- "!**/internal/handler/**.go"
deny:
- pkg: github.com/FerretDB/FerretDB/internal/handler/commonerrors
- pkg: github.com/FerretDB/FerretDB/internal/handler/handlererrors
exhaustive:
default-signifies-exhaustive: false
gci:
Expand Down
12 changes: 6 additions & 6 deletions internal/clientconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/FerretDB/FerretDB/internal/clientconn/conninfo"
"github.com/FerretDB/FerretDB/internal/clientconn/connmetrics"
"github.com/FerretDB/FerretDB/internal/handler"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/handler/proxy"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand Down Expand Up @@ -255,7 +255,7 @@ func (c *conn) run(ctx context.Context) (err error) {
// TODO https://github.com/FerretDB/FerretDB/issues/2412

// get protocol error to return correct error document
protoErr := commonerrors.ProtocolError(validationErr)
protoErr := handlererrors.ProtocolError(validationErr)

var res wire.OpMsg
must.NoError(res.SetSections(wire.OpMsgSection{
Expand Down Expand Up @@ -476,7 +476,7 @@ func (c *conn) route(ctx context.Context, reqHeader *wire.MsgHeader, reqBody wir
if err != nil {
switch resHeader.OpCode {
case wire.OpCodeMsg:
protoErr := commonerrors.ProtocolError(err)
protoErr := handlererrors.ProtocolError(err)

var res wire.OpMsg
must.NoError(res.SetSections(wire.OpMsgSection{
Expand All @@ -485,9 +485,9 @@ func (c *conn) route(ctx context.Context, reqHeader *wire.MsgHeader, reqBody wir
resBody = &res

switch protoErr := protoErr.(type) {
case *commonerrors.CommandError:
case *handlererrors.CommandError:
result = protoErr.Code().String()
case *commonerrors.WriteErrors:
case *handlererrors.WriteErrors:
result = "write-error"
default:
panic(fmt.Errorf("unexpected error type %T", protoErr))
Expand Down Expand Up @@ -574,7 +574,7 @@ func (c *conn) handleOpMsg(ctx context.Context, msg *wire.OpMsg, command string)

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

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

// logResponse logs response's header and body and returns the log level that was used.
Expand Down
6 changes: 3 additions & 3 deletions internal/handler/cmd_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

"github.com/FerretDB/FerretDB/internal/handler/common"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/must"
"github.com/FerretDB/FerretDB/internal/wire"
Expand Down Expand Up @@ -53,8 +53,8 @@ func (h *Handler) CmdQuery(ctx context.Context, query *wire.OpQuery) (*wire.OpRe
}, nil
}

return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNotImplemented,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrNotImplemented,
fmt.Sprintf("CmdQuery: unhandled command %q for collection %q", cmd, collection),
"OpQuery: "+cmd,
)
Expand Down
22 changes: 11 additions & 11 deletions internal/handler/common/add_fields_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"

"github.com/FerretDB/FerretDB/internal/handler/common/aggregations/operators"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand Down Expand Up @@ -102,33 +102,33 @@ func processAddFieldsError(err error) error {

switch opErr.Code() {
case operators.ErrTooManyFields:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrAddFieldsExpressionWrongAmountOfArgs,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrAddFieldsExpressionWrongAmountOfArgs,
"Invalid $addFields :: caused by :: FieldPath field names may not start with '$'."+
" Consider using $getField or $setField.",
"$addFields (stage)",
)
case operators.ErrNotImplemented:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNotImplemented,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrNotImplemented,
"Invalid $addFields :: caused by :: "+opErr.Error(),
"$addFields (stage)",
)
case operators.ErrArgsInvalidLen:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrOperatorWrongLenOfArgs,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrOperatorWrongLenOfArgs,
"Invalid $addFields :: caused by :: "+opErr.Error(),
"$addFields (stage)",
)
case operators.ErrInvalidExpression:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrInvalidPipelineOperator,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrInvalidPipelineOperator,
"Invalid $addFields :: caused by :: "+opErr.Error(),
"$addFields (stage)",
)
case operators.ErrInvalidNestedExpression:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrInvalidPipelineOperator,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrInvalidPipelineOperator,
"Invalid $addFields :: caused by :: "+opErr.Error(),
"$addFields (stage)",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"errors"
"fmt"

"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/must"
Expand All @@ -46,17 +46,17 @@ type Accumulator interface {
func NewAccumulator(stage, key string, value any) (Accumulator, error) {
accumulation, ok := value.(*types.Document)
if !ok || accumulation.Len() == 0 {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrStageGroupInvalidAccumulator,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrStageGroupInvalidAccumulator,
fmt.Sprintf("The field '%s' must be an accumulator object", key),
stage+" (stage)",
)
}

// accumulation document contains only one field.
if accumulation.Len() > 1 {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrStageGroupMultipleAccumulator,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrStageGroupMultipleAccumulator,
fmt.Sprintf("The field '%s' must specify one accumulator", key),
stage+" (stage)",
)
Expand Down Expand Up @@ -90,8 +90,8 @@ func NewAccumulator(stage, key string, value any) (Accumulator, error) {

newAccumulator, ok := Accumulators[operator]
if !ok {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNotImplemented,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrNotImplemented,
fmt.Sprintf("%s accumulator %q is not implemented yet", stage, operator),
operator+" (accumulator)",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package accumulators
import (
"errors"

"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
)
Expand All @@ -28,8 +28,8 @@ type count struct{}
// newCount creates a new $count aggregation operator.
func newCount(args ...any) (Accumulator, error) {
if len(args) != 1 {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrStageGroupUnaryOperator,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrStageGroupUnaryOperator,
"The $count accumulator is a unary operator",
"$count (accumulator)",
)
Expand All @@ -38,8 +38,8 @@ func newCount(args ...any) (Accumulator, error) {
doc, ok := args[0].(*types.Document)

if !ok || doc.Len() > 0 {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrTypeMismatch,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrTypeMismatch,
"$count takes no arguments, i.e. $count:{}",
"$count (accumulator)",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/FerretDB/FerretDB/internal/handler/common/aggregations"
"github.com/FerretDB/FerretDB/internal/handler/common/aggregations/operators"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand All @@ -37,8 +37,8 @@ func newSum(args ...any) (Accumulator, error) {
accumulator := new(sum)

if len(args) != 1 {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrStageGroupUnaryOperator,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrStageGroupUnaryOperator,
"The $sum accumulator is a unary operator",
"$sum (accumulator)",
)
Expand Down
38 changes: 19 additions & 19 deletions internal/handler/common/aggregations/operators/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/FerretDB/FerretDB/internal/handler/common/aggregations"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand Down Expand Up @@ -239,32 +239,32 @@ func processExprOperatorErrors(err error, argument string) error {
case errors.As(err, &opErr):
switch opErr.Code() {
case ErrTooManyFields:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrExpressionWrongLenOfFields,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrExpressionWrongLenOfFields,
"An object representing an expression must have exactly one field",
argument,
)
case ErrNotImplemented:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNotImplemented,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrNotImplemented,
"Invalid $match :: caused by :: "+opErr.Error(),
argument,
)
case ErrArgsInvalidLen:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrOperatorWrongLenOfArgs,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrOperatorWrongLenOfArgs,
opErr.Error(),
argument,
)
case ErrInvalidExpression:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrInvalidPipelineOperator,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrInvalidPipelineOperator,
fmt.Sprintf("Unrecognized expression '%s'", opErr.Name()),
argument,
)
case ErrInvalidNestedExpression:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrInvalidPipelineOperator,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrInvalidPipelineOperator,
opErr.Error(),
argument,
)
Expand All @@ -273,27 +273,27 @@ func processExprOperatorErrors(err error, argument string) error {
case errors.As(err, &exErr):
switch exErr.Code() {
case aggregations.ErrInvalidExpression:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrFailedToParse,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrFailedToParse,
fmt.Sprintf("'%s' starts with an invalid character for a user variable name", exErr.Name()),
argument,
)
case aggregations.ErrEmptyFieldPath:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrGroupInvalidFieldPath,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrGroupInvalidFieldPath,
"'$' by itself is not a valid FieldPath",
argument,
)
case aggregations.ErrUndefinedVariable:
// TODO https://github.com/FerretDB/FerretDB/issues/2275
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrNotImplemented,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrNotImplemented,
"Aggregation expression variables are not implemented yet",
argument,
)
case aggregations.ErrEmptyVariable:
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrFailedToParse,
return handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrFailedToParse,
"empty variable names are not allowed",
argument,
)
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/common/aggregations/operators/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/FerretDB/FerretDB/internal/handler/common/aggregations"
"github.com/FerretDB/FerretDB/internal/handler/commonparams"
"github.com/FerretDB/FerretDB/internal/handler/handlerparams"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
)
Expand Down Expand Up @@ -119,7 +119,7 @@ func (t *typeOp) Process(doc *types.Document) (any, error) {
}
}

return commonparams.AliasFromType(res), nil
return handlerparams.AliasFromType(res), nil
}

// check interfaces
Expand Down
6 changes: 3 additions & 3 deletions internal/handler/common/aggregations/stages/add_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/FerretDB/FerretDB/internal/handler/common"
"github.com/FerretDB/FerretDB/internal/handler/common/aggregations"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand All @@ -42,8 +42,8 @@ func newAddFields(stage *types.Document) (aggregations.Stage, error) {

fieldsDoc, ok := fields.(*types.Document)
if !ok {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrSetBadExpression,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrSetBadExpression,
fmt.Sprintf("$addFields specification stage must be an object, got %T", fields),
"$addFields (stage)",
)
Expand Down
10 changes: 5 additions & 5 deletions internal/handler/common/aggregations/stages/collstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/FerretDB/FerretDB/internal/handler/common"
"github.com/FerretDB/FerretDB/internal/handler/common/aggregations"
"github.com/FerretDB/FerretDB/internal/handler/commonerrors"
"github.com/FerretDB/FerretDB/internal/handler/commonparams"
"github.com/FerretDB/FerretDB/internal/handler/handlererrors"
"github.com/FerretDB/FerretDB/internal/handler/handlerparams"
"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/iterator"
"github.com/FerretDB/FerretDB/internal/util/lazyerrors"
Expand All @@ -46,8 +46,8 @@ type storageStats struct {
func newCollStats(stage *types.Document) (aggregations.Stage, error) {
fields, err := common.GetRequiredParam[*types.Document](stage, "$collStats")
if err != nil {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrStageCollStatsInvalidArg,
return nil, handlererrors.NewCommandErrorMsgWithArgument(
handlererrors.ErrStageCollStatsInvalidArg,
fmt.Sprintf("$collStats must take a nested object but found: %s", types.FormatAnyValue(stage)),
"$collStats (stage)",
)
Expand All @@ -74,7 +74,7 @@ func newCollStats(stage *types.Document) (aggregations.Stage, error) {

var s any
if s, err = storageStatsFields.Get("scale"); err == nil {
scale, err := commonparams.GetValidatedNumberParamWithMinValue(
scale, err := handlerparams.GetValidatedNumberParamWithMinValue(
"$collStats.storageStats", "scale", s, 1,
)
if err != nil {
Expand Down

0 comments on commit eaaceea

Please sign in to comment.