Merge pull request #57591 from nextcloud/carl/query-exception

refactor(QueryException): Remove most usage of QueryException
This commit is contained in:
Carl Schwan 2026-01-20 15:59:56 +01:00 committed by GitHub
commit 4c79c2faff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 29 additions and 32 deletions

View file

@ -14,7 +14,7 @@ use OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin;
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use Psr\Container\ContainerExceptionInterface;
use Sabre\DAV\Collection;
use Sabre\DAV\ServerPlugin;
use function array_map;
@ -229,7 +229,7 @@ class PluginManager {
private function createClass(string $className): object {
try {
return $this->container->get($className);
} catch (QueryException $e) {
} catch (ContainerExceptionInterface $e) {
if (class_exists($className)) {
return new $className();
}

View file

@ -9,8 +9,8 @@ declare(strict_types=1);
namespace OCA\DAV\CalDAV\Reminder;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
use OCP\AppFramework\QueryException;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
/**
* Class NotificationProviderManager
@ -55,7 +55,7 @@ class NotificationProviderManager {
* Registers a new provider
*
* @param string $providerClassName
* @throws QueryException
* @throws ContainerExceptionInterface
*/
public function registerProvider(string $providerClassName):void {
$provider = Server::get($providerClassName);

View file

@ -15,7 +15,6 @@ use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
use OCA\DAV\ConfigLexicon;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\QueryException;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
@ -83,7 +82,7 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
try {
$trustedServers = Server::get(TrustedServers::class);
$request = Server::get(IRequest::class);
} catch (QueryException|NotFoundExceptionInterface|ContainerExceptionInterface $e) {
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
// nothing to do, the request / trusted servers don't exist
}
if ($addressBook['principaluri'] === 'principals/system/system') {

View file

@ -17,7 +17,6 @@ use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use OCP\Constants;
use OCP\IConfig;
use OCP\IGroup;
@ -27,6 +26,7 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\IManager as IShareManager;
use Psr\Container\ContainerExceptionInterface;
use Sabre\DAV\Exception;
use Sabre\DAV\PropPatch;
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
@ -539,7 +539,7 @@ class Principal implements BackendInterface {
try {
$circle = Circles::detailsCircle($circleUniqueId, true);
} catch (QueryException $ex) {
} catch (ContainerExceptionInterface $ex) {
return null;
} catch (CircleNotFoundException $ex) {
return null;
@ -563,7 +563,7 @@ class Principal implements BackendInterface {
* @param string $principal
* @return array
* @throws Exception
* @throws QueryException
* @throws ContainerExceptionInterface
* @suppress PhanUndeclaredClassMethod
*/
public function getCircleMembership($principal):array {

View file

@ -14,7 +14,7 @@ use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
use OCA\DAV\Capabilities;
use OCP\AppFramework\QueryException;
use Psr\Container\ContainerExceptionInterface;
use Test\TestCase;
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
@ -22,7 +22,7 @@ class NotificationProviderManagerTest extends TestCase {
private NotificationProviderManager $providerManager;
/**
* @throws QueryException
* @throws ContainerExceptionInterface
*/
protected function setUp(): void {
parent::setUp();
@ -65,7 +65,7 @@ class NotificationProviderManagerTest extends TestCase {
}
/**
* @throws QueryException
* @throws ContainerExceptionInterface
*/
public function testRegisterBadProvider(): void {
$this->expectException(\InvalidArgumentException::class);

View file

@ -20,8 +20,7 @@ use OCP\IUser;
class ResourceProvider implements IProvider {
public const RESOURCE_TYPE = 'file';
/** @var array */
protected $nodes = [];
protected array $nodes = [];
public function __construct(
protected IRootFolder $rootFolder,

View file

@ -51,7 +51,6 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Group\Events\BeforeGroupDeletedEvent;
use OCP\Group\Events\GroupDeletedEvent;
@ -60,6 +59,7 @@ use OCP\Group\Events\UserRemovedEvent;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\User\Events\UserDeletedEvent;
use Psr\Container\ContainerExceptionInterface;
/**
* @package OCA\Files_External\AppInfo
@ -70,7 +70,7 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
/**
* Application constructor.
*
* @throws QueryException
* @throws ContainerExceptionInterface
*/
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);

View file

@ -16,7 +16,6 @@ use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\QueryException;
use OCP\Files\Config\IAuthoritativeMountProvider;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Mount\IMountPoint;
@ -28,6 +27,7 @@ use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
use OCP\Server;
use Psr\Clock\ClockInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
/**
@ -57,7 +57,7 @@ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider {
/**
* Process storage ready for mounting
*
* @throws QueryException
* @throws ContainerExceptionInterface
*/
private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void {
foreach ($storage->getBackendOptions() as $option => $value) {

View file

@ -15,12 +15,12 @@ use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\QueryException;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
use OCP\Server;
use phpseclib\Crypt\AES;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
/**
@ -48,7 +48,7 @@ class MountConfig {
* @param mixed $input
* @param string|null $userId
* @return mixed
* @throws QueryException
* @throws ContainerExceptionInterface
* @since 16.0.0
*/
public static function substitutePlaceholdersInConfig($input, ?string $userId = null) {

View file

@ -181,10 +181,10 @@ class DeletedShareAPIController extends OCSController {
* Returns the helper of DeletedShareAPIController for room shares.
*
* If the Talk application is not enabled or the helper is not available
* a QueryException is thrown instead.
* a ContainerExceptionInterface is thrown instead.
*
* @psalm-suppress UndefinedClass
* @throws QueryException
* @throws ContainerExceptionInterface
*/
private function getRoomShareHelper(): \OCA\Talk\Share\Helper\DeletedShareAPIController {
if (!$this->appManager->isEnabledForUser('spreed')) {
@ -199,10 +199,10 @@ class DeletedShareAPIController extends OCSController {
* Returns the helper of DeletedShareAPIHelper for deck shares.
*
* If the Deck application is not enabled or the helper is not available
* a QueryException is thrown instead.
* a ContainerExceptionInterface is thrown instead.
*
* @psalm-suppress UndefinedClass
* @throws QueryException
* @throws ContainerExceptionInterface
*/
private function getDeckShareHelper(): \OCA\Deck\Sharing\ShareAPIHelper {
if (!$this->appManager->isEnabledForUser('deck')) {

View file

@ -13,6 +13,7 @@ use OC\AppFramework\Utility\SimpleContainer;
use OC\ServerContainer;
use OCP\IConfig;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
/**
@ -90,7 +91,7 @@ class App {
try {
$this->container = \OC::$server->getRegisteredAppContainer($appName);
} catch (QueryException $e) {
} catch (ContainerExceptionInterface $e) {
$this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
}
}

View file

@ -11,7 +11,6 @@
namespace OCP;
use Closure;
use OCP\AppFramework\QueryException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -37,7 +36,6 @@ interface IContainer extends ContainerInterface {
* @since 8.2.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
* @throws ContainerExceptionInterface if the class could not be found or instantiated
* @throws QueryException if the class could not be found or instantiated
*/
public function resolve($name);
@ -53,7 +51,6 @@ interface IContainer extends ContainerInterface {
* @psalm-return ($name is class-string ? T : mixed)
* @throws ContainerExceptionInterface if the query could not be resolved
* @throws NotFoundExceptionInterface if the name could not be found within the container
* @throws QueryException if the query could not be resolved
* @since 6.0.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
*/

View file

@ -10,7 +10,8 @@ declare(strict_types=1);
namespace OCP\Log;
use OC;
use OCP\AppFramework\QueryException;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use function class_exists;
@ -45,14 +46,14 @@ function logger(?string $appId = null): LoggerInterface {
try {
$appContainer = OC::$server->getRegisteredAppContainer($appId);
return $appContainer->get(LoggerInterface::class);
} catch (QueryException $e) {
} catch (ContainerExceptionInterface $e) {
// Ignore and return the server logger below
}
}
try {
return OC::$server->get(LoggerInterface::class);
} catch (QueryException $e) {
return Server::get(LoggerInterface::class);
} catch (ContainerExceptionInterface $e) {
return new NullLogger();
}
}