From 4dcf8d5dd346d3b0432fbce2a312d4527d22ea55 Mon Sep 17 00:00:00 2001 From: Robert Weide <41573936+RobertWeideKyos@users.noreply.github.com> Date: Fri, 16 May 2025 16:57:50 +0200 Subject: [PATCH] Fix issue with out of bounds log index See https://github.com/opcodesio/log-viewer/discussions/451 --- src/Readers/IndexedLogReader.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Readers/IndexedLogReader.php b/src/Readers/IndexedLogReader.php index dac753e2..43f1008f 100644 --- a/src/Readers/IndexedLogReader.php +++ b/src/Readers/IndexedLogReader.php @@ -236,9 +236,9 @@ public function paginate(int $perPage = 25, ?int $page = null) { $page = $page ?: Paginator::resolveCurrentPage('page'); - if (! is_null($this->onlyShowIndex)) { + if (! is_null($this->onlyShowIndex) && $index = $this->reset()->getLogAtIndex($this->onlyShowIndex)) { return new LengthAwarePaginator( - [$this->reset()->getLogAtIndex($this->onlyShowIndex)], + [$index], 1, $perPage, $page @@ -291,7 +291,9 @@ public function percentScanned(): int protected function getLogAtIndex(int $index): ?Log { - $position = $this->index()->getPositionForIndex($index); + if (! $position = $this->index()->getPositionForIndex($index)) { + return null; + } $text = $this->getLogTextAtPosition($position);