refactor: Expose a public exception when no user is found

And use this new exception everywhere outside of where the old one was
throw.

Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
Carl Schwan 2026-06-23 16:58:13 +02:00 committed by Anna
parent fc52f6f66a
commit da0928827a
45 changed files with 125 additions and 112 deletions

View file

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace OCA\DAV\BackgroundJob;
use OC\User\NoUserException;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException;
use OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException;
use OCA\DAV\CalDAV\Reminder\ReminderService;
@ -34,7 +33,6 @@ class EventReminderJob extends TimedJob {
/**
* @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
* @throws NoUserException
*/
#[\Override]
public function run($argument):void {

View file

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace OCA\DAV\BackgroundJob;
use OC\User\NoUserException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
@ -19,6 +18,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\Server;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
class UploadCleanup extends TimedJob {
@ -46,7 +46,7 @@ class UploadCleanup extends TimedJob {
/** @var Folder $uploads */
$uploads = $userRoot->get('uploads');
$uploadFolder = $uploads->get($folder);
} catch (NotFoundException|NoUserException $e) {
} catch (NotFoundException|UserNotFoundException $e) {
$this->jobList->remove(self::class, $argument);
return;
}

View file

@ -10,7 +10,6 @@ namespace OCA\DAV\Connector\Sabre;
use OC\AppFramework\Http\Request;
use OC\FilesMetadata\Model\FilesMetadata;
use OC\User\NoUserException;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\Files_Sharing\External\Mount as SharingExternalMount;
use OCP\Accounts\IAccountManager;
@ -29,6 +28,7 @@ use OCP\IPreview;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\User\Exceptions\UserNotFoundException;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile;
@ -382,7 +382,7 @@ class FilesPlugin extends ServerPlugin {
// Check if the user published their display name
try {
$ownerAccount = $this->accountManager->getAccount($owner);
} catch (NoUserException) {
} catch (UserNotFoundException) {
// do not lock process if owner is not local
return null;
}

View file

@ -11,12 +11,12 @@ namespace OCA\DAV\SystemTag;
use OC\SystemTag\SystemTag;
use OC\SystemTag\SystemTagsInFilesDetector;
use OC\User\NoUserException;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\User\Exceptions\UserNotFoundException;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\SimpleCollection;
@ -63,7 +63,7 @@ class SystemTagsInUseCollection extends SimpleCollection {
if ($user) {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
}
} catch (NoUserException) {
} catch (UserNotFoundException) {
// will throw a Sabre exception in the next step.
}
if ($user === null || $userFolder === null) {

View file

@ -13,7 +13,6 @@ use Closure;
use Exception;
use OC\Files\Filesystem;
use OC\Files\View;
use OC\User\NoUserException;
use OCA\Encryption\Util;
use OCA\Files\Exception\TransferOwnershipException;
use OCA\Files_External\Config\ConfigAdapter;
@ -35,6 +34,7 @@ use OCP\Server;
use OCP\Share\Events\ShareTransferredEvent;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
@ -67,7 +67,7 @@ class OwnershipTransferService {
* @param OutputInterface|null $output
* @param bool $move
* @throws TransferOwnershipException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function transfer(
IUser $sourceUser,

View file

@ -10,7 +10,6 @@ namespace OCA\Files_External\Command;
use OC\Core\Command\Base;
use OC\Files\Filesystem;
use OC\User\NoUserException;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\DefinitionParameter;
@ -22,6 +21,7 @@ use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -179,7 +179,7 @@ class Create extends Base {
$user = $this->userManager->get($userId);
if (is_null($user)) {
throw new NoUserException("user $userId not found");
throw UserNotFoundException::createForUser($userId);
}
$this->userSession->setUser($user);
return $this->userService;

View file

@ -9,7 +9,6 @@
namespace OCA\Files_External\Command;
use OC\Core\Command\Base;
use OC\User\NoUserException;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\GlobalStoragesService;
@ -18,6 +17,7 @@ use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -174,7 +174,7 @@ class Import extends Base {
$user = $this->userManager->get($userId);
if (is_null($user)) {
throw new NoUserException("user $userId not found");
throw UserNotFoundException::createForUser($userId);
}
$this->userSession->setUser($user);
return $this->userService;

View file

@ -9,13 +9,13 @@
namespace OCA\Files_External\Command;
use OC\Core\Command\Base;
use OC\User\NoUserException;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -234,7 +234,7 @@ class ListCommand extends Base {
$user = $this->userManager->get($userId);
if (is_null($user)) {
throw new NoUserException("user $userId not found");
throw UserNotFoundException::createForUser($userId);
}
$this->userSession->setUser($user);
return $this->userService;

View file

@ -17,7 +17,6 @@ return array(
'OCA\\FilesReminders\\Db\\ReminderMapper' => $baseDir . '/../lib/Db/ReminderMapper.php',
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => $baseDir . '/../lib/Exception/NodeNotFoundException.php',
'OCA\\FilesReminders\\Exception\\ReminderNotFoundException' => $baseDir . '/../lib/Exception/ReminderNotFoundException.php',
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => $baseDir . '/../lib/Exception/UserNotFoundException.php',
'OCA\\FilesReminders\\Listener\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listener/LoadAdditionalScriptsListener.php',
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => $baseDir . '/../lib/Listener/NodeDeletedListener.php',
'OCA\\FilesReminders\\Listener\\SabrePluginAddListener' => $baseDir . '/../lib/Listener/SabrePluginAddListener.php',

View file

@ -32,7 +32,6 @@ class ComposerStaticInitFilesReminders
'OCA\\FilesReminders\\Db\\ReminderMapper' => __DIR__ . '/..' . '/../lib/Db/ReminderMapper.php',
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/NodeNotFoundException.php',
'OCA\\FilesReminders\\Exception\\ReminderNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/ReminderNotFoundException.php',
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/UserNotFoundException.php',
'OCA\\FilesReminders\\Listener\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScriptsListener.php',
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/NodeDeletedListener.php',
'OCA\\FilesReminders\\Listener\\SabrePluginAddListener' => __DIR__ . '/..' . '/../lib/Listener/SabrePluginAddListener.php',

View file

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\FilesReminders\Exception;
use Exception;
class UserNotFoundException extends Exception {
}

View file

@ -16,7 +16,6 @@ use OCA\FilesReminders\Db\Reminder;
use OCA\FilesReminders\Db\ReminderMapper;
use OCA\FilesReminders\Exception\NodeNotFoundException;
use OCA\FilesReminders\Exception\ReminderNotFoundException;
use OCA\FilesReminders\Exception\UserNotFoundException;
use OCA\FilesReminders\Model\RichReminder;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\Folder;
@ -28,6 +27,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
use Throwable;
@ -165,7 +165,7 @@ class ReminderService {
$user = $this->userManager->get($reminder->getUserId());
if ($user === null) {
throw new UserNotFoundException();
throw UserNotFoundException::createForUser($reminder->getUserId());
}
$notification = $this->notificationManager->createNotification();

View file

@ -9,7 +9,6 @@
namespace OCA\Files_Sharing\External;
use OC\Files\Filesystem;
use OC\User\NoUserException;
use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent;
use OCA\Files_Sharing\Helper;
use OCP\AppFramework\Db\DoesNotExistException;
@ -35,6 +34,7 @@ use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
class Manager {
@ -67,7 +67,7 @@ class Manager {
*
* @throws Exception
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function addShare(ExternalShare $externalShare, IUser|IGroup|null $shareWith = null): ?Mount {
$shareWith = $shareWith ?? $this->user;

View file

@ -8,11 +8,11 @@ declare(strict_types=1);
namespace OCA\Files_Sharing;
use OC\User\NoUserException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\User\Exceptions\UserNotFoundException;
class OrphanHelper {
public function __construct(
@ -25,7 +25,7 @@ class OrphanHelper {
public function isShareValid(string $owner, int $fileId): bool {
try {
$userFolder = $this->rootFolder->getUserFolder($owner);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
return false;
}
$node = $userFolder->getFirstNodeById($fileId);

View file

@ -22,7 +22,6 @@ use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\Storage\Wrapper\Wrapper;
use OC\Files\View;
use OC\Share\Share;
use OC\User\NoUserException;
use OCA\Files_Sharing\ISharedStorage as LegacyISharedStorage;
use OCP\Constants;
use OCP\Files\Cache\ICache;
@ -43,6 +42,7 @@ use OCP\Lock\ILockingProvider;
use OCP\Server;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Override;
use Psr\Log\LoggerInterface;
@ -193,13 +193,8 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage
'mask' => $this->superShare->getPermissions(),
]);
}
} catch (NotFoundException $e) {
// original file not accessible or deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';
} catch (NoUserException $e) {
// sharer user deleted, set FailedStorage
} catch (NotFoundException|UserNotFoundException $e) {
// original file not accessible or deleted or sharer user deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';

View file

@ -15,7 +15,6 @@ use OC\Files\Filesystem;
use OC\Files\Node\NonExistingFile;
use OC\Files\Node\NonExistingFolder;
use OC\Files\View;
use OC\User\NoUserException;
use OC_User;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Trashbin\Command\Expire;
@ -53,6 +52,7 @@ use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -81,7 +81,7 @@ class Trashbin implements IEventListener {
*
* @param string $filename
* @return array
* @throws NoUserException
* @throws UserNotFoundException
*/
public static function getUidAndFilename($filename) {
$uid = Filesystem::getOwner($filename);

View file

@ -7,10 +7,10 @@
namespace OCA\Files_Versions\Sabre;
use OC\User\NoUserException;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\IRootFolder;
use OCP\IUserManager;
use OCP\User\Exceptions\UserNotFoundException;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\ICollection;
@ -27,8 +27,8 @@ class VersionHome implements ICollection {
private function getUser() {
[, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
$user = $this->userManager->get($name);
if (!$user) {
throw new NoUserException();
if ($user === null) {
throw UserNotFoundException::createForUser($name);
}
return $user;
}

View file

@ -43,6 +43,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Server;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Psr\Log\LoggerInterface;
@ -90,7 +91,7 @@ class Storage {
*
* @param string $filename
* @return array
* @throws NoUserException
* @throws UserNotFoundException
*/
public static function getUidAndFilename($filename) {
$uid = Filesystem::getOwner($filename);
@ -844,6 +845,7 @@ class Storage {
* @param string $filename path to file to expire
* @param string $uid user for which to expire the version
* @return bool|int|null
* @throws UserNotFoundException
*/
public static function expire($filename, $uid) {
$expiration = self::getExpiration();

View file

@ -15,7 +15,6 @@ use OC\Files\Filesystem;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\SystemConfig;
use OC\User\NoUserException;
use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files_Versions\Db\VersionEntity;
use OCA\Files_Versions\Db\VersionsMapper;
@ -30,6 +29,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
/**
@ -634,7 +634,7 @@ class VersioningTest extends \Test\TestCase {
}
public function testExpireNonexistingUser(): void {
$this->expectException(NoUserException::class);
$this->expectException(UserNotFoundException::class);
$this->logout();
// needed to have a FS setup (the background job does this)

View file

@ -11,7 +11,6 @@ namespace OCA\Provisioning_API\Controller;
use OC\Group\Manager as GroupManager;
use OC\User\Backend;
use OC\User\NoUserException;
use OCA\Provisioning_API\ResponseDefinitions;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
@ -32,6 +31,7 @@ use OCP\L10N\IFactory;
use OCP\Server;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
/**
@ -115,7 +115,7 @@ abstract class AUserDataOCSController extends OCSController {
# from the external source (reasons unknown to us)
# cf. https://github.com/nextcloud/server/issues/12991
$data['storageLocation'] = $targetUserObject->getHome();
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
throw new OCSNotFoundException($e->getMessage(), $e);
}
}

View file

@ -9,7 +9,6 @@
namespace OCA\Provisioning_API\Tests\Controller;
use OC\Group\Manager;
use OC\User\NoUserException;
use OCA\Provisioning_API\Controller\GroupsController;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\OCS\OCSException;
@ -22,6 +21,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\UserInterface;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
@ -460,7 +460,7 @@ class GroupsControllerTest extends \Test\TestCase {
];
$users['ncu2']->expects($this->atLeastOnce())
->method('getHome')
->willThrowException(new NoUserException());
->willThrowException(new UserNotFoundException());
$this->userManager->expects($this->any())
->method('get')
@ -504,7 +504,7 @@ class GroupsControllerTest extends \Test\TestCase {
];
$users['ncu2']->expects($this->atLeastOnce())
->method('getHome')
->willThrowException(new NoUserException());
->willThrowException(new UserNotFoundException());
$this->userManager->expects($this->any())
->method('get')

View file

@ -10,7 +10,6 @@ namespace OCA\ShareByMail;
use OC\Share20\DefaultShareProvider;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Share;
use OC\User\NoUserException;
use OCA\ShareByMail\Settings\SettingsManager;
use OCP\Activity\IManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
@ -38,6 +37,7 @@ use OCP\Share\IAttributes;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\Share\IShareProviderWithNotification;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Psr\Log\LoggerInterface;
@ -1071,7 +1071,7 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
private function getNode(string $userId, int $id): Node {
try {
$userFolder = $this->rootFolder->getUserFolder($userId);
} catch (NoUserException $e) {
} catch (UserNotFoundException) {
throw new InvalidShare();
}

View file

@ -9,7 +9,6 @@
namespace OCA\Testing\Controller;
use OC\Lock\DBLockingProvider;
use OC\User\NoUserException;
use OCA\Testing\Locking\FakeDBLockingProvider;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@ -22,6 +21,7 @@ use OCP\IDBConnection;
use OCP\IRequest;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\User\Exceptions\UserNotFoundException;
class LockingController extends OCSController {
@ -57,7 +57,7 @@ class LockingController extends OCSController {
}
/**
* @throws NotFoundException
* @throws UserNotFoundException
*/
protected function getPath(string $user, string $path): string {
$node = $this->rootFolder->getUserFolder($user)->get($path);
@ -82,7 +82,7 @@ class LockingController extends OCSController {
public function acquireLock(int $type, string $user, string $path): DataResponse {
try {
$path = $this->getPath($user, $path);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
} catch (NotFoundException $e) {
throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
@ -105,7 +105,7 @@ class LockingController extends OCSController {
public function changeLock(int $type, string $user, string $path): DataResponse {
try {
$path = $this->getPath($user, $path);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
} catch (NotFoundException $e) {
throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
@ -128,7 +128,7 @@ class LockingController extends OCSController {
public function releaseLock(int $type, string $user, string $path): DataResponse {
try {
$path = $this->getPath($user, $path);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
} catch (NotFoundException $e) {
throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
@ -151,7 +151,7 @@ class LockingController extends OCSController {
public function isLocked(int $type, string $user, string $path): DataResponse {
try {
$path = $this->getPath($user, $path);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
} catch (NotFoundException $e) {
throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);

View file

@ -10,7 +10,6 @@ declare(strict_types=1);
namespace OCA\Theming\Service;
use InvalidArgumentException;
use OC\User\NoUserException;
use OCA\Theming\AppInfo\Application;
use OCP\Files\File;
use OCP\Files\IAppData;
@ -24,6 +23,7 @@ use OCP\IConfig;
use OCP\Image;
use OCP\Lock\LockedException;
use OCP\PreConditionNotMetException;
use OCP\User\Exceptions\UserNotFoundException;
use RuntimeException;
class BackgroundService {
@ -226,12 +226,11 @@ class BackgroundService {
}
/**
* @param $path
* @throws NotFoundException
* @throws NotPermittedException
* @throws LockedException
* @throws PreConditionNotMetException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function setFileBackground(string $path, ?string $userId = null): void {
$userId = $userId ?? $this->getUserId();

View file

@ -10,11 +10,11 @@ declare(strict_types=1);
namespace OCA\WorkflowEngine\Command;
use OC\Core\Command\Base;
use OC\User\NoUserException;
use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Manager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\WorkflowEngine\IManager;
use Override;
use Symfony\Component\Console\Input\InputArgument;
@ -74,7 +74,7 @@ class Runtime extends Base {
if ($userId !== null) {
$user = $this->userManager->get($userId);
if ($user === null) {
throw new NoUserException("user $userId not found");
throw UserNotFoundException::createForUser($userId);
}
$this->userSession->setUser($user);
$this->manager->reloadRuntimeOperations();

View file

@ -9,12 +9,12 @@ declare(strict_types=1);
namespace OC\Core\Command\FilesMetadata;
use OC\User\NoUserException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\User\Exceptions\UserNotFoundException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -66,7 +66,7 @@ class Get extends Command {
/**
* @throws NotPermittedException
* @throws FilesMetadataNotFoundException
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
*/
#[\Override]

View file

@ -8,7 +8,6 @@ declare(strict_types=1);
namespace OC\Core\Command\Info;
use OC\User\NoUserException;
use OCA\Circles\MountManager\CircleMount;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\Files_Sharing\SharedMount;
@ -26,6 +25,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IDBConnection;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Symfony\Component\Console\Output\OutputInterface;
@ -44,7 +44,7 @@ class FileUtils {
* @param FileInfo $file
* @return array<string, Node[]>
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
*/
public function getFilesByUser(FileInfo $file): array {
$id = $file->getId();

View file

@ -1058,6 +1058,7 @@ return array(
'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php',
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
'OCP\\User\\Events\\UserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/UserLoggedOutEvent.php',
'OCP\\User\\Exceptions\\UserNotFoundException' => $baseDir . '/lib/public/User/Exceptions/UserNotFoundException.php',
'OCP\\User\\GetQuotaEvent' => $baseDir . '/lib/public/User/GetQuotaEvent.php',
'OCP\\User\\IAvailabilityCoordinator' => $baseDir . '/lib/public/User/IAvailabilityCoordinator.php',
'OCP\\User\\IOutOfOfficeData' => $baseDir . '/lib/public/User/IOutOfOfficeData.php',

View file

@ -1099,6 +1099,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\User\\Events\\UserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInEvent.php',
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
'OCP\\User\\Events\\UserLoggedOutEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedOutEvent.php',
'OCP\\User\\Exceptions\\UserNotFoundException' => __DIR__ . '/../../..' . '/lib/public/User/Exceptions/UserNotFoundException.php',
'OCP\\User\\GetQuotaEvent' => __DIR__ . '/../../..' . '/lib/public/User/GetQuotaEvent.php',
'OCP\\User\\IAvailabilityCoordinator' => __DIR__ . '/../../..' . '/lib/public/User/IAvailabilityCoordinator.php',
'OCP\\User\\IOutOfOfficeData' => __DIR__ . '/../../..' . '/lib/public/User/IOutOfOfficeData.php',

View file

@ -11,7 +11,6 @@ namespace OC\Avatar;
use OC\KnownUser\KnownUserService;
use OC\User\Manager;
use OC\User\NoUserException;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\Files\IAppData;
@ -23,6 +22,7 @@ use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUserSession;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
/**
@ -119,7 +119,7 @@ class AvatarManager implements IAvatarManager {
$this->logger->debug("No cache for the user $userId. Ignoring avatar deletion");
} catch (NotPermittedException|StorageNotAvailableException $e) {
$this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion");
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
$this->logger->debug("Account $userId not found. Ignoring avatar deletion");
}
$this->config->deleteUserValue($userId, 'avatar', 'generated');

View file

@ -8,7 +8,6 @@ declare(strict_types=1);
namespace OC\Collaboration\Reference\File;
use OC\User\NoUserException;
use OCP\Collaboration\Reference\ADiscoverableReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\Reference;
@ -22,6 +21,7 @@ use OCP\IPreview;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\User\Exceptions\UserNotFoundException;
class FileReferenceProvider extends ADiscoverableReferenceProvider {
private ?string $userId;
@ -132,7 +132,7 @@ class FileReferenceProvider extends ADiscoverableReferenceProvider {
'mtime' => $file->getMTime(),
'preview-available' => $this->previewManager->isAvailable($file)
]);
} catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) {
} catch (InvalidPathException|NotFoundException|NotPermittedException|UserNotFoundException $e) {
throw new NotFoundException();
}
}

View file

@ -12,10 +12,10 @@ use OC\Encryption\Util;
use OC\Files\Filesystem;
use OC\Files\View;
use OC\ServerNotAvailableException;
use OC\User\NoUserException;
use OCP\Encryption\Keys\IStorage;
use OCP\IConfig;
use OCP\Security\ICrypto;
use OCP\User\Exceptions\UserNotFoundException;
class Storage implements IStorage {
/** @var string hidden file which indicate that the folder is a valid key storage */
@ -121,7 +121,7 @@ class Storage implements IStorage {
try {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return !$this->view->file_exists($path) || $this->view->unlink($path);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
// this exception can come from initMountPoints() from setupUserMounts()
// for a deleted user.
//

View file

@ -24,6 +24,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
class Filesystem {
@ -342,7 +343,7 @@ class Filesystem {
/**
* Initialize system and personal mount points for a user
*
* @throws NoUserException if the user is not available
* @throws UserNotFoundException if the user is not available
*/
public static function initMountPoints(string|IUser|null $user = ''): void {
/** @var IUserManager $userManager */

View file

@ -315,19 +315,13 @@ class Root extends Folder implements IRootFolder, Emitter {
return '';
}
/**
* Returns a view to user's files folder
*
* @param string $userId user ID
* @return \OCP\Files\Folder
* @throws NoUserException
* @throws NotPermittedException
*/
#[\Override]
public function getUserFolder($userId) {
$userObject = $this->userManager->get($userId);
if (is_null($userObject)) {
// Change this to UserNotFoundException in the future when all consumers
// are ported to the new exception
$e = new NoUserException('Backends provided no user object');
$this->logger->error(
sprintf(

View file

@ -12,7 +12,6 @@ namespace OC\Files\Template;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Files\Cache\Scanner;
use OC\Files\Filesystem;
use OC\User\NoUserException;
use OCA\Files\ResponseDefinitions;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
@ -36,6 +35,7 @@ use OCP\IPreview;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\User\Exceptions\UserNotFoundException;
use Override;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@ -185,7 +185,7 @@ class TemplateManager implements ITemplateManager {
/**
* @throws NotFoundException
* @throws NotPermittedException
* @throws NoUserException
* @throws UserNotFoundException
*/
private function getTemplateFolder(): Folder {
if ($this->getTemplatePath() !== '') {

View file

@ -19,7 +19,6 @@ use OC\Lock\NoopLockingProvider;
use OC\Share\Share;
use OC\User\LazyUser;
use OC\User\Manager as UserManager;
use OC\User\NoUserException;
use OC\User\User;
use OCA\Files_Sharing\SharedMount;
use OCP\Constants;
@ -52,6 +51,7 @@ use OCP\Lock\LockedException;
use OCP\Server;
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\Util;
use Psr\Log\LoggerInterface;
@ -2270,7 +2270,7 @@ class View {
/**
* @param string $filename
* @return array
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotFoundException
*/
public function getUidAndFilename($filename) {

View file

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace OC\SpeechToText;
use OC\User\NoUserException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\EventDispatcher\IEventDispatcher;
@ -21,6 +20,7 @@ use OCP\PreConditionNotMetException;
use OCP\SpeechToText\Events\TranscriptionFailedEvent;
use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent;
use OCP\SpeechToText\ISpeechToTextManager;
use OCP\User\Exceptions\UserNotFoundException;
use Psr\Log\LoggerInterface;
class TranscriptionJob extends QueuedJob {
@ -72,7 +72,7 @@ class TranscriptionJob extends QueuedJob {
$appId,
)
);
} catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|NoUserException $e) {
} catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|UserNotFoundException $e) {
$this->logger->warning('Transcription of file ' . $fileId . ' failed', ['exception' => $e]);
$this->eventDispatcher->dispatchTyped(
new TranscriptionFailedEvent(

View file

@ -12,6 +12,7 @@ namespace OC\User;
use OCP\IImage;
use OCP\IUser;
use OCP\IUserManager;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\UserInterface;
class LazyUser implements IUser {
@ -37,7 +38,7 @@ class LazyUser implements IUser {
}
if ($this->user === null) {
throw new NoUserException('User not found in backend');
throw UserNotFoundException::createForUser($this->uid);
}
return $this->user;

View file

@ -36,6 +36,7 @@ use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\User\Backend\ISearchKnownUsersBackend;
use OCP\User\Events\BeforeUserCreatedEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\User\Exceptions\UserNotFoundException;
use OCP\UserInterface;
use OCP\Util;
use Psr\Log\LoggerInterface;
@ -327,7 +328,7 @@ class Manager extends PublicEmitter implements IUserManager {
return mb_stripos($user->getUID(), $search) !== false
|| mb_stripos($user->getDisplayName(), $search) !== false
|| mb_stripos($user->getEMailAddress() ?? '', $search) !== false;
} catch (NoUserException $ex) {
} catch (UserNotFoundException $ex) {
$this->logger->error('Error while filtering disabled users', ['exception' => $ex, 'userUID' => $user->getUID()]);
return false;
}

View file

@ -10,5 +10,7 @@ declare(strict_types=1);
namespace OC\User;
class NoUserException extends \Exception {
use OCP\User\Exceptions\UserNotFoundException;
class NoUserException extends UserNotFoundException {
}

View file

@ -8,10 +8,10 @@
namespace OCP\Files;
use OC\User\NoUserException;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node as INode;
use OCP\User\Exceptions\UserNotFoundException;
/**
* Interface IRootFolder
@ -24,7 +24,7 @@ interface IRootFolder extends Folder {
*
* @param string $userId user ID
* @return Folder
* @throws NoUserException
* @throws UserNotFoundException
* @throws NotPermittedException
*
* @since 8.2.0

View file

@ -8,11 +8,14 @@
namespace OCP;
use OCP\User\Exceptions\UserNotFoundException;
/**
* Interface for managing and querying user session state.
*
* Provides methods for authenticating users, accessing the active user,
* and handling login/logout functionality in a Nextcloud server session.
*
* @since 6.0.0
*/
interface IUserSession {
@ -89,6 +92,7 @@ interface IUserSession {
* If false, removes any impersonator information from the session.
*
* @param bool $useCurrentUser Whether to assign the current user as the impersonator or to clear it.
* @throws UserNotFoundException When the user is not found
* @since 18.0.0
*/
public function setImpersonatingUserID(bool $useCurrentUser = true): void;

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\User\Exceptions;
use OCP\AppFramework\Attribute\Catchable;
use OCP\AppFramework\Attribute\Throwable;
/**
* The class UserNotFoundException is thrown when no user is found.
*
* @since 35.0.0
*/
#[Throwable(since: '35.0.0')]
#[Catchable(since: '35.0.0')]
class UserNotFoundException extends \Exception {
/**
* Return a UserNotFoundException with a standard error message.
*
* @since 35.0.0
*/
public static function createForUser(string $userId, ?\Exception $previous = null): self {
return new UserNotFoundException('User with ' . $userId . ' not found.', previous: $previous);
}
}

View file

@ -12,7 +12,6 @@ use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\User\NoUserException;
use OCP\Files;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IMountProviderCollection;
@ -24,6 +23,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use OCP\User\Exceptions\UserNotFoundException;
class DummyMountProvider implements IMountProvider {
/**
@ -330,7 +330,7 @@ class FilesystemTest extends \Test\TestCase {
*
*/
public function testLocalMountWhenUserDoesNotExist(): void {
$this->expectException(NoUserException::class);
$this->expectException(UserNotFoundException::class);
$userId = $this->getUniqueID('user_');
@ -338,7 +338,7 @@ class FilesystemTest extends \Test\TestCase {
}
public function testNullUserThrows(): void {
$this->expectException(NoUserException::class);
$this->expectException(UserNotFoundException::class);
Filesystem::initMountPoints(null);
}
@ -347,12 +347,12 @@ class FilesystemTest extends \Test\TestCase {
$thrown = 0;
try {
Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
$thrown++;
}
try {
Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
$thrown++;
}
$this->assertEquals(2, $thrown);
@ -367,13 +367,13 @@ class FilesystemTest extends \Test\TestCase {
try {
Filesystem::initMountPoints($userId);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
$thrown++;
}
try {
Filesystem::initMountPoints($userId);
} catch (NoUserException $e) {
} catch (UserNotFoundException $e) {
$thrown++;
}

View file

@ -15,7 +15,6 @@ use OC\Files\Node\Root;
use OC\Files\Storage\Storage;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OC\User\NoUserException;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
@ -25,6 +24,7 @@ use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use OCP\User\Exceptions\UserNotFoundException;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
@ -220,7 +220,7 @@ class RootTest extends \Test\TestCase {
}
public function testGetUserFolderWithNoUserObj(): void {
$this->expectException(NoUserException::class);
$this->expectException(UserNotFoundException::class);
$this->expectExceptionMessage('Backends provided no user object');
$root = new Root(