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

Panic in ToInt64 Function in util package When Handling int32 and smaller integer Types #155

Open
ahmed-hossam28 opened this issue Sep 3, 2024 · 2 comments

Comments

@ahmed-hossam28
Copy link
Contributor

Hi there!
While testing queries, I encountered a panic when passing an int32 value to a query that i found uses ToInt64 function. The function converts only uint64 and int64 types to int64. If an int, int32, or any other type is passed, the function panics with the message “not a number” so i wondered if it was intended to converts int64 and uint64 only.

func ToInt64(v interface{}) int64 {
	switch vType := v.(type) {
	case uint64:
		return int64(vType)
	case int64:
		return vType
	}
	panic("not a number")
}
@ostafen
Copy link
Owner

ostafen commented Sep 3, 2024

@ahmed-hossam28: yes, It Is intended for int64 only, but panic should not happen while executing queries, so sounds like there is an issue somewhere.
Could you please share the query which causes the panic?

@ahmed-hossam28
Copy link
Contributor Author

This is what is was testing.

.....
documents := []*d.Document{doc1, doc2}

	// Create a new query to find documents where age is greater than 30
	q := query.NewQuery("users")
	q = q.Where(query.Field("age").In(int32(20)))

	// Iterate over documents and apply query
	for _, doc := range documents {
		if q.Satisfy(doc) {
			fmt.Println("Matching Document:", doc)
		}
	}

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

No branches or pull requests

2 participants