Skip to content

Commit 09c4f15

Browse files
committed
handle json encoding error
1 parent 00a3361 commit 09c4f15

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,10 @@ public function logBatchCounter(array $metrics, int $batchSize = self::INSERT_BA
773773
$row = $this->prepareMetricRow($metricData);
774774
if ($row) {
775775
$encoded = json_encode($row);
776-
if ($encoded) {
777-
$rows[] = $encoded;
776+
if ($encoded === false) {
777+
throw new Exception("Failed to JSON encode metric row: " . json_last_error_msg());
778778
}
779+
$rows[] = $encoded;
779780
}
780781
}
781782

@@ -873,9 +874,10 @@ public function logBatch(array $metrics, int $batchSize = self::INSERT_BATCH_SIZ
873874
$row = $this->prepareMetricRow($metricData);
874875
if ($row) {
875876
$encoded = json_encode($row);
876-
if ($encoded) {
877-
$rows[] = $encoded;
877+
if ($encoded === false) {
878+
throw new Exception("Failed to JSON encode metric row: " . json_last_error_msg());
878879
}
880+
$rows[] = $encoded;
879881
}
880882
}
881883

0 commit comments

Comments
 (0)