nilaway
nilaway copied to clipboard
Not catching possible type assertion exceptions?
First of all I love this library and think it is a great addition to the Golang community, thank you for your hard work for it.
I got a nil pointer exception, but did not see a nilaway error when checking the code:
root := data["root"].(map[string]interface{})
children := root["children"].([]interface{})
Full code for context:
// Check if the response status is OK
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("vespa query failed with status %d", resp.StatusCode)
}
// Read the response body
dataBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var data map[string]interface{}
err = json.Unmarshal(dataBytes, &data)
if err != nil {
panic(err)
}
root := data["root"].(map[string]interface{})
children := root["children"].([]interface{}) // <- This has thrown exceptions for me
If the response does not conform to the expert assertions, it will panic.
Hi! Type assertions are not fully handled in NilAway right now, which is why you're seeing the false negative here. I'm keeping this issue open to track the efforts :)