Skip to content

Commit

Permalink
fix: update return responses
Browse files Browse the repository at this point in the history
  • Loading branch information
c-harish authored and benbarten committed Nov 27, 2024
1 parent 131df63 commit ccabe05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 1 addition & 2 deletions internal/errors/migrated_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ var (
ErrInvalidIPAddress = errors.New("invalid IP address")
ErrInvalidFingerprint = errors.New("invalid fingerprint")
ErrKeyDoesNotExist = errors.New("ERR could not perform this operation on a key that doesn't exist")
ErrInvalidFloat = errors.New("ERR value is not a valid float")
ErrUnsupportedUnit = errors.New("ERR unsupported unit provided. please use m, km, ft, mi")
ErrUnsupportedUnit = errors.New("ERR unsupported unit provided. please use M, KM, FT, MI")

// Error generation functions for specific error messages with dynamic parameters.
ErrWrongArgumentCount = func(command string) error {
Expand Down
21 changes: 12 additions & 9 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6989,7 +6989,7 @@ func parseGeoRadiusOpts(args []string) (*geoRadiusOpts, error) {
}
i++
} else {
return nil, diceerrors.ErrGeneral("syntax error")
return nil, diceerrors.ErrSyntax
}
case "ANY":
return nil, diceerrors.ErrGeneral("the ANY argument requires COUNT argument")
Expand All @@ -7002,7 +7002,7 @@ func parseGeoRadiusOpts(args []string) (*geoRadiusOpts, error) {
opts.StoreDist = false
i++
} else {
return nil, diceerrors.ErrGeneral("syntax error")
return nil, diceerrors.ErrSyntax
}
case "STOREDIST":
if opts.WithCoord || opts.WithDist || opts.WithHash {
Expand All @@ -7013,10 +7013,10 @@ func parseGeoRadiusOpts(args []string) (*geoRadiusOpts, error) {
opts.StoreDist = true
i++
} else {
return nil, diceerrors.ErrGeneral("syntax error")
return nil, diceerrors.ErrSyntax
}
default:
return nil, diceerrors.ErrGeneral("syntax error")
return nil, diceerrors.ErrSyntax
}
}

Expand All @@ -7027,7 +7027,7 @@ func evalGEORADIUSBYMEMBER(args []string, store *dstore.Store) *EvalResponse {
if len(args) < 4 {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrWrongArgumentCount("GEODIST"),
Error: diceerrors.ErrWrongArgumentCount("GEORADIUSBYMEMBER"),
}
}

Expand All @@ -7039,7 +7039,8 @@ func evalGEORADIUSBYMEMBER(args []string, store *dstore.Store) *EvalResponse {
distVal, parseErr := strconv.ParseFloat(dist, 64)
if parseErr != nil {
return &EvalResponse{
Error: diceerrors.ErrInvalidFloat,
Result: nil,
Error: diceerrors.ErrGeneral("need numeric radius"),
}
}

Expand All @@ -7054,22 +7055,24 @@ func evalGEORADIUSBYMEMBER(args []string, store *dstore.Store) *EvalResponse {
obj := store.Get(key)
if obj == nil {
return &EvalResponse{
Result: clientio.NIL,
Result: clientio.EmptyArray,
Error: nil,
}
}

ss, err := sortedset.FromObject(obj)
if err != nil {
return &EvalResponse{
Error: diceerrors.ErrWrongTypeOperation,
Result: nil,
Error: diceerrors.ErrWrongTypeOperation,
}
}

centerHash, ok := ss.Get(member)
if !ok {
return &EvalResponse{
Result: nil,
Error: nil,
Error: diceerrors.ErrGeneral("could not decode requested zset member"),
}
}

Expand Down

0 comments on commit ccabe05

Please sign in to comment.