Skip to content

Commit

Permalink
Merge branch 'main' into issue-1317-fix-schema-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 8, 2022
2 parents 17b6e7a + 0b83d17 commit b117bd4
Show file tree
Hide file tree
Showing 38 changed files with 303 additions and 187 deletions.
3 changes: 2 additions & 1 deletion internal/clientconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ func (c *conn) handleOpMsg(ctx context.Context, msg *wire.OpMsg, cmd string) (*w
}

errMsg := fmt.Sprintf("no such command: '%s'", cmd)
return nil, common.NewErrorMsg(common.ErrCommandNotFound, errMsg)

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

// logResponse logs response's header and body and returns the log level that was used.
Expand Down
16 changes: 10 additions & 6 deletions internal/handlers/common/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type ProtoErr interface {
Code() ErrorCode
// Document returns *types.Document.
Document() *types.Document
// Info returns *Info.
// Info returns *ErrInfo.
Info() *ErrInfo
}

Expand Down Expand Up @@ -159,28 +159,32 @@ func ProtocolError(err error) (ProtoErr, bool) {
func formatBitwiseOperatorErr(err error, operator string, maskValue any) error {
switch err {
case errNotWholeNumber:
return NewCommandErrorMsg(
return NewCommandErrorMsgWithArgument(
ErrFailedToParse,
fmt.Sprintf("Expected an integer: %s: %#v", operator, maskValue),
operator,
)

case errNegativeNumber:
if _, ok := maskValue.(float64); ok {
return NewCommandErrorMsg(
return NewCommandErrorMsgWithArgument(
ErrFailedToParse,
fmt.Sprintf(`Expected a non-negative number in: %s: %.1f`, operator, maskValue),
operator,
)
}

return NewCommandErrorMsg(
return NewCommandErrorMsgWithArgument(
ErrFailedToParse,
fmt.Sprintf(`Expected a non-negative number in: %s: %v`, operator, maskValue),
operator,
)

case errNotBinaryMask:
return NewCommandErrorMsg(
return NewCommandErrorMsgWithArgument(
ErrBadValue,
fmt.Sprintf(`value takes an Array, a number, or a BinData but received: %s: %#v`, operator, maskValue),
operator,
)

default:
Expand All @@ -198,7 +202,7 @@ func CheckError(err error) error {

switch ve.Code() {
case types.ErrValidation, types.ErrIDNotFound:
return NewErrorMsg(ErrBadValue, err.Error())
return NewCommandErrorMsg(ErrBadValue, err.Error())
case types.ErrWrongIDType:
return NewWriteErrorMsg(ErrInvalidID, err.Error())
default:
Expand Down
14 changes: 0 additions & 14 deletions internal/handlers/common/error_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ func NewCommandError(code ErrorCode, err error) error {
}
}

// NewError is a deprecated alias for NewCommandError.
//
// Deprecated: use NewCommandError instead.
func NewError(code ErrorCode, err error) error {
return NewCommandError(code, err)
}

// NewCommandErrorMsg is variant for NewCommandError with error string.
//
// Code shouldn't be zero, err can't be empty.
Expand All @@ -71,13 +64,6 @@ func NewCommandErrorMsgWithArgument(code ErrorCode, msg string, argument string)
}
}

// NewErrorMsg is a deprecated alias for NewCommandErrorMsg.
//
// Deprecated: use NewCommandErrorMsg instead.
func NewErrorMsg(code ErrorCode, msg string) error {
return NewCommandErrorMsg(code, msg)
}

// Error implements error interface.
func (e *CommandError) Error() string {
return fmt.Sprintf("%[1]s (%[1]d): %[2]v", e.code, e.err)
Expand Down
Loading

0 comments on commit b117bd4

Please sign in to comment.