Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not catching possible type assertion exceptions? #150

Open
stevelizcano opened this issue Dec 6, 2023 · 1 comment
Open

Not catching possible type assertion exceptions? #150

stevelizcano opened this issue Dec 6, 2023 · 1 comment

Comments

@stevelizcano
Copy link

stevelizcano commented Dec 6, 2023

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.

@yuxincs
Copy link
Contributor

yuxincs commented Dec 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants