Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 3.5.0 [unreleased]

1. [#149](https://github.com/influxdata/influxdb-client-php/issues/149): Throw exception on empty field

## 3.4.0 [2023-07-28]

### Bug Fixes
Expand Down
5 changes: 3 additions & 2 deletions src/InfluxDB2/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ public function time($time, $precision = null): Point
return $this;
}

/** If there is no field then return null.
/** If there is no field then throw an exception.
*
* @return string representation of the point
* @throws \InvalidArgumentException when no field is provided
*/
public function toLineProtocol()
{
Expand All @@ -135,7 +136,7 @@ public function toLineProtocol()
$fields = $this->appendFields();

if ($this->isNullOrEmptyString($fields)) {
return null;
throw new \InvalidArgumentException("Failed to write Point: At least one field is required.");
}

$lineProtocol .= $fields;
Expand Down
5 changes: 4 additions & 1 deletion tests/PointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DateTimeImmutable;
use InfluxDB2\Model\WritePrecision;
use InfluxDB2\Point;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

class PointTest extends TestCase
Expand Down Expand Up @@ -262,11 +263,13 @@ public function testWithoutTags()

public function testWithoutFields()
{
$this->expectException(\InvalidArgumentException::class);

$point = Point::measurement('h2o')
->addTag('location', 'europe')
->time(123);

$this->assertNull($point->toLineProtocol());
$point->toLineProtocol();
}

public function testFromArrayWithoutName()
Expand Down