nilaway icon indicating copy to clipboard operation
nilaway copied to clipboard

Not catching possible type assertion exceptions?

Open stevelizcano opened this issue 1 year ago • 1 comments

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.

stevelizcano avatar Dec 06 '23 04:12 stevelizcano

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 :)

yuxincs avatar Dec 07 '23 23:12 yuxincs