Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix(LogErrors): Handle unsupported log_type gracefully #1451

Open
wants to merge 1 commit into
base: stable29
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Exception/UnsupportedLogTypeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\LogReader\Exception;

class UnsupportedLogTypeException extends \Exception {
public function __construct() {
parent::__construct('Logreader application only supports "file" log_type');
}
}
3 changes: 2 additions & 1 deletion lib/Log/LogIteratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\LogReader\Log;

use OCA\LogReader\Exception\UnsupportedLogTypeException;
use OCP\IConfig;
use OCP\Log\IFileBased;
use OCP\Log\ILogFactory;
Expand All @@ -44,7 +45,7 @@ public function getLogIterator(array $levels): \Iterator {
$timezone = $this->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) {
Expand Down
5 changes: 5 additions & 0 deletions lib/SetupChecks/LogErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
namespace OCA\LogReader\SetupChecks;

use OCA\LogReader\Exception\UnsupportedLogTypeException;
use OCA\LogReader\Log\LogIteratorFactory;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
Expand Down Expand Up @@ -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()])
);
Expand Down
Loading