ostafen/clover

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

ahmed-hossam28 opened this issue · 2 comments

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")
}

@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?

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