Skip to content

Commit

Permalink
add Search_Config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kmrmt committed Jan 23, 2025
1 parent 8179e7d commit eb8e500
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/errors/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ var (

// ErrIndexNotFound represents an error that the index not found.
ErrIndexNotFound = New("index not found")

// ErrNilSearch_Config represents an error that the Search_Config is nil.
ErrNilSearch_Config = New("Search_Config is nil")
)
4 changes: 4 additions & 0 deletions pkg/gateway/lb/handler/grpc/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (s *server) aggregationSearch(
}
}()

if bcfg == nil {
return nil, nil, errors.ErrNilSearch_Config
}

num := aggr.GetNum()
min := int(bcfg.GetMinNum())

Expand Down
22 changes: 22 additions & 0 deletions pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ func (s *server) doSearch(
}
}()

if cfg == nil {
err = errors.ErrNilSearch_Config
err = status.WrapWithInvalidArgument(apiName+"/doSearch", err, &errdetails.RequestInfo{
RequestId: "Search_Config is nil",
ServingData: "Search_Config is nil",
},
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequestFieldViolation{
{
Field: "Search_Config is nil",
Description: err.Error(),
},
},
})
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeInvalidArgument(err.Error())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, nil, err
}

var (
num = int(cfg.GetNum())
fnum int
Expand Down

0 comments on commit eb8e500

Please sign in to comment.