From 1fc8096d7b593f7a1ab0ed4ea0126e169c8ce8e3 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 000000000..c88322f03 --- /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 1c2aacd53..7a821d20b 100644 --- a/lib/SetupChecks/LogErrors.php +++ b/lib/SetupChecks/LogErrors.php @@ -25,6 +25,7 @@ */ namespace OCA\LogReader\SetupChecks; +use OCA\LogReader\Exception\UnsupportedLogTypeException; use OCA\LogReader\Log\LogIteratorFactory; use OCP\IConfig; use OCP\IDateTimeFormatter; @@ -57,6 +58,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()]) );