InfluxCommunity / influxdb3-go

The go package that provides a simple and convenient way to interact with InfluxDB 3.
https://pkg.go.dev/github.com/InfluxCommunity/influxdb3-go
MIT License
21 stars 11 forks source link

QueryIterator should not panic on error #79

Open alespour opened 3 months ago

alespour commented 3 months ago

Specifications

Code sample to reproduce problem

When result contains unsupported data type, the following calls may cause panic.

ok := iterator.Next()
// or
pv := iterator.AsPoints()

https://github.com/InfluxCommunity/influxdb3-go/blob/94c8385fe546fabbfc38dbf958ec439c3f625ddb/influxdb3/query_iterator.go#L88 https://github.com/InfluxCommunity/influxdb3-go/blob/94c8385fe546fabbfc38dbf958ec439c3f625ddb/influxdb3/query_iterator.go#L108

Expected behavior

Next() and AsPoints() should not panic, but somehow return error.

Next methods could be changed according to these iterator guidelines and AsPoints similarly. ie

func (i *QueryIterator) Next() (map[string]interface{}, error) // how about adding a new type (or alias) for the value?
func (i *QueryIterator) AsPoints() (*PointValues, error)

This renders Value method useless, btw.

So perhaps adding a new iterator type designed according to the guidelines, and deprecating the existing one would be a better solution.

Actual behavior

panic may occur

Additional info

No response