Skip to content

Commit 9132fc0

Browse files
committed
fix(LogErrors): Handle unsupported log_type gracefully
Signed-off-by: provokateurin <[email protected]>
1 parent 61dab73 commit 9132fc0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\LogReader\Exception;
11+
12+
class UnsupportedLogTypeException extends \Exception {
13+
public function __construct() {
14+
parent::__construct('Logreader application only supports "file" log_type');
15+
}
16+
}

lib/Log/LogIteratorFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\LogReader\Log;
1010

11+
use OCA\LogReader\Exception\UnsupportedLogTypeException;
1112
use OCP\IConfig;
1213
use OCP\Log\IFileBased;
1314
use OCP\Log\ILogFactory;
@@ -29,7 +30,7 @@ public function getLogIterator(array $levels): \Iterator {
2930
$timezone = $this->config->getSystemValue('logtimezone', 'UTC');
3031
$logType = $this->config->getSystemValue('log_type', 'file');
3132
if ($logType !== 'file') {
32-
throw new \Exception('Logreader application only supports "file" log_type');
33+
throw new UnsupportedLogTypeException();
3334
}
3435
$log = $this->logFactory->get('file');
3536
if ($log instanceof IFileBased) {

lib/SetupChecks/LogErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
namespace OCA\LogReader\SetupChecks;
1010

11+
use OCA\LogReader\Exception\UnsupportedLogTypeException;
1112
use OCA\LogReader\Log\LogIteratorFactory;
1213
use OCP\IConfig;
1314
use OCP\IDateTimeFormatter;
@@ -40,6 +41,10 @@ public function run(): SetupResult {
4041
try {
4142
$logIterator = $this->logIteratorFactory->getLogIterator([self::LEVEL_WARNING,self::LEVEL_ERROR,self::LEVEL_FATAL]);
4243
} catch (\Exception $e) {
44+
if ($e instanceof UnsupportedLogTypeException) {
45+
return SetupResult::info($e->getMessage());
46+
}
47+
4348
return SetupResult::error(
4449
$this->l10n->t('Failed to get an iterator for log entries: %s', [$e->getMessage()])
4550
);

0 commit comments

Comments
 (0)