Skip to content

refactor: Expose a public exception when no user is found#61544

Open
CarlSchwan wants to merge 1 commit into
masterfrom
carl/nouserexception
Open

refactor: Expose a public exception when no user is found#61544
CarlSchwan wants to merge 1 commit into
masterfrom
carl/nouserexception

Conversation

@CarlSchwan

Copy link
Copy Markdown
Member

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

  • Resolves: #

Summary

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@CarlSchwan CarlSchwan added this to the Nextcloud 35 milestone Jun 23, 2026
@CarlSchwan CarlSchwan self-assigned this Jun 23, 2026
@CarlSchwan CarlSchwan added the 3. to review Waiting for reviews label Jun 23, 2026
@CarlSchwan CarlSchwan requested review from a team, blizzz and nickvergessen as code owners June 23, 2026 14:59
@CarlSchwan CarlSchwan added technical debt 🧱 🤔🚀 pending documentation This pull request needs an associated documentation update labels Jun 23, 2026
@CarlSchwan CarlSchwan requested review from ArtificialOwl, come-nc, icewind1991 and provokateurin and removed request for a team June 23, 2026 14:59
@CarlSchwan CarlSchwan force-pushed the carl/nouserexception branch from c476514 to efa25e8 Compare June 23, 2026 15:14
Comment thread lib/public/User/Exceptions/UserNotFoundException.php Outdated
susnux
susnux previously requested changes Jun 23, 2026

@susnux susnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All throw UserNotFoundException must be reverted to throw NoUserFoundException otherwise legacy code cannot catch them.

Comment thread lib/private/User/Session.php Outdated

if ($currentUser === null) {
throw new NoUserException();
throw new UserNotFoundException();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work.

Old code still catches NoUserException throwing UserNotFoundException is the parent class.
Meaning the catch does not work anymore as the now thrown exception is less specific.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The throw UserNotFoundException I ported were all in commands and are just to display a nice error message when running occ and are not catched. I left the one in lib/private/Files/Filesystem.php and lib/private/Files/Node/Root.php as before.

The one in Session can be argue for. It's at the moment not documented and the method is not used https://github.com/search?q=org%3Anextcloud+setImpersonatingUserID&type=code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The throw UserNotFoundException I ported were all in commands and are just to display a nice error message when running occ and are not catched.

That makes sense

I left the one in lib/private/Files/Filesystem.php and lib/private/Files/Node/Root.php as before.

Then ok!

@CarlSchwan CarlSchwan force-pushed the carl/nouserexception branch from efa25e8 to 8a0c1c6 Compare June 23, 2026 15:33
And use this new exception everywhere outside of where the old one was
throw.

Signed-off-by: Carl Schwan <carlschwan@kde.org>
@CarlSchwan CarlSchwan force-pushed the carl/nouserexception branch from 8a0c1c6 to 8ecce9d Compare June 23, 2026 15:34
@susnux susnux dismissed their stale review June 23, 2026 16:29

resolved

@susnux susnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good now

use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\User\Events\PostLoginEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\User\Exceptions\UserNotFoundException;

@nickvergessen nickvergessen Jun 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray import?
Edit: CS agrees

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews pending documentation This pull request needs an associated documentation update technical debt 🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants