From 9132fc07ec1ad0477df03da8d0572b8b34ea579b Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 18 Dec 2024 19:06:56 +0100 Subject: [PATCH] fix(LogErrors): Handle unsupported log_type gracefully Signed-off-by: provokateurin --- lib/Exception/UnsupportedLogTypeException.php | 16 ++++++++++++++++ lib/Log/LogIteratorFactory.php | 3 ++- lib/SetupChecks/LogErrors.php | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/Exception/UnsupportedLogTypeException.php diff --git a/lib/Exception/UnsupportedLogTypeException.php b/lib/Exception/UnsupportedLogTypeException.php new file mode 100644 index 00000000..c88322f0 --- /dev/null +++ b/lib/Exception/UnsupportedLogTypeException.php @@ -0,0 +1,16 @@ +config->getSystemValue('logtimezone', 'UTC'); $logType = $this->config->getSystemValue('log_type', 'file'); if ($logType !== 'file') { - throw new \Exception('Logreader application only supports "file" log_type'); + throw new UnsupportedLogTypeException(); } $log = $this->logFactory->get('file'); if ($log instanceof IFileBased) { diff --git a/lib/SetupChecks/LogErrors.php b/lib/SetupChecks/LogErrors.php index f08cf8af..b3d5646b 100644 --- a/lib/SetupChecks/LogErrors.php +++ b/lib/SetupChecks/LogErrors.php @@ -8,6 +8,7 @@ */ namespace OCA\LogReader\SetupChecks; +use OCA\LogReader\Exception\UnsupportedLogTypeException; use OCA\LogReader\Log\LogIteratorFactory; use OCP\IConfig; use OCP\IDateTimeFormatter; @@ -40,6 +41,10 @@ public function run(): SetupResult { try { $logIterator = $this->logIteratorFactory->getLogIterator([self::LEVEL_WARNING,self::LEVEL_ERROR,self::LEVEL_FATAL]); } catch (\Exception $e) { + if ($e instanceof UnsupportedLogTypeException) { + return SetupResult::info($e->getMessage()); + } + return SetupResult::error( $this->l10n->t('Failed to get an iterator for log entries: %s', [$e->getMessage()]) );