Skip to content

Commit

Permalink
lint: assert type and panic if it fails
Browse files Browse the repository at this point in the history
This commit checks type assertions and panic if the assertion fails.
  • Loading branch information
maeb committed May 14, 2024
1 parent 6f8f002 commit 5184250
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/keyvalue/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func NewReportGenerator(g index.ReportGenerator) (*ReportGenerator, error) {
// }

func mapRequestToStructPb(req index.Request) (*structpb.Struct, error) {
values := req.(*api.SearchRequest).Values
searchReq, ok := req.(*api.SearchRequest)
if !ok {
panic("assert: req (index.Request) is not a *api.SearchRequest")
}
values := searchReq.Values
m := make(map[string]interface{}, len(values))
for k, v := range values {
if len(v) == 1 {
Expand Down Expand Up @@ -132,6 +136,7 @@ func (r ReportGenerator) Generate(ctx context.Context, req index.Request) (*sche
surtDomain, prevSurtDomain string
ts, prevTs time.Time
path, prevPath string
ok bool
)

updateCount := 0
Expand All @@ -147,7 +152,10 @@ func (r ReportGenerator) Generate(ctx context.Context, req index.Request) (*sche
tock = true
default:
}
resp = result.(CdxResponse)
resp, ok = result.(CdxResponse)
if !ok {
panic("assert: result (index.CdxResponse) is not a keyvalue.CdxResponse")
}
key = resp.Key
cdx = resp.Value

Expand Down

0 comments on commit 5184250

Please sign in to comment.