Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
smsunarto committed Nov 13, 2023
1 parent 4b05fdc commit 227c176
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
8 changes: 3 additions & 5 deletions cardinal/ecs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,9 @@ func validateQuery[Request any, Reply any](
}

if !repValid || !reqValid {
return errors.New(
fmt.Sprintf(
"invalid query: %s: the Request and Reply generics must be both structs",
name,
),
return fmt.Errorf(
"invalid query: %s: the Request and Reply generics must be both structs",
name,
)
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions cardinal/ecs/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ func RegisterQuery[Request any, Reply any](
func (w *World) GetQueryByName(name string) (Query, error) {
if q, ok := w.nameToQuery[name]; ok {
return q, nil
} else {
return nil, fmt.Errorf("query with name %s not found", name)
}
return nil, fmt.Errorf("query with name %s not found", name)
}

func (w *World) RegisterMessages(txs ...message.Message) error {
Expand Down Expand Up @@ -649,8 +648,10 @@ func (w *World) RecoverFromChain(ctx context.Context) error {
"be sure to use the `WithAdapter` option when creating the world")
}
if w.CurrentTick() > 0 {
return fmt.Errorf("world recovery should not occur in a world with existing state. please verify all " +
"state has been cleared before running recovery")
return fmt.Errorf(
"world recovery should not occur in a world with existing state. please verify all " +
"state has been cleared before running recovery",
)
}

w.isRecovering = true
Expand Down
14 changes: 12 additions & 2 deletions cardinal/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type QueryHealthResponse struct {
IDs []cardinal.EntityID
}

func handleQueryHealth(worldCtx cardinal.WorldContext, request *QueryHealthRequest) (*QueryHealthResponse, error) {
func handleQueryHealth(
worldCtx cardinal.WorldContext,
request *QueryHealthRequest,
) (*QueryHealthResponse, error) {
q, err := worldCtx.NewSearch(cardinal.Exact(Health{}))
if err != nil {
return nil, err
Expand Down Expand Up @@ -65,7 +68,14 @@ func TestNewQueryTypeWithEVMSupport(t *testing.T) {
func TestQueryExample(t *testing.T) {
world, _ := testutils.MakeWorldAndTicker(t)
assert.NilError(t, cardinal.RegisterComponent[Health](world))
assert.NilError(t, cardinal.RegisterQuery[QueryHealthRequest, QueryHealthResponse](world, "query_health", handleQueryHealth))
assert.NilError(
t,
cardinal.RegisterQuery[QueryHealthRequest, QueryHealthResponse](
world,
"query_health",
handleQueryHealth,
),
)

worldCtx := testutils.WorldToWorldContext(world)
ids, err := cardinal.CreateMany(worldCtx, 100, Health{})
Expand Down
2 changes: 1 addition & 1 deletion cardinal/server/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (handler *Handler) registerQueryHandlerSwagger(api *untyped.API) error {
return middleware.Error(
http.StatusNotFound,
fmt.Errorf("query %s not found", queryTypeString),
), nil
), nil //lint:ignore nilerr this is a middleware error that should 404
}

bodyData, ok := mapStruct["queryBody"]
Expand Down

0 comments on commit 227c176

Please sign in to comment.