influxdata/influxdb-php

Exception using getPoints on empty metric

Opened this issue · 3 comments

andig commented

PHP Warning: Invalid argument supplied for foreach() in src/InfluxDB/ResultSet.php on line 68

Getting this warning when writing against Telegraf v1 listener

andig commented

I think root cause is getSeries which has meanwhile been modified:

    public function getSeries()
    {
        $series = array_map(
            function ($object) {
                if (isset($object['error'])) {
                    throw new ClientException($object['error']);
                }

                return isset($object['series']) ? $object['series'] : [];
            },
            $this->parsedResults['results']
        );

        return array_shift($series);
    }

array_shift($series); on empty array will yield NULL and hence yield the notice.

andig commented

Seems this was changed in ba96a93. However, upgrading to 1.15, I'm getting:

In ResultSet.php line 107: Invalid statement index provided  
andig commented

I feel the reason is that in

$series = $this->getSeries();
getSeries() is called without parameter which means default value of 0.

In getSeries(), in

if ($queryIndex !== null && !array_key_exists($queryIndex, $results)) {
this will throw when the result does not contain any and hence no 0 series.

Is that the desired behaviour?