Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(notifications): Add a dedicated exception when a notification was…
… not parsed completely

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Apr 12, 2024
commit 0d0c2cdaa08f6bc8f547b437a5b046914680b3f5
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php',
'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php',
'OCP\\Notification\\IncompleteNotificationException' => $baseDir . '/lib/public/Notification/IncompleteNotificationException.php',
'OCP\\Notification\\IncompleteParsedNotificationException' => $baseDir . '/lib/public/Notification/IncompleteParsedNotificationException.php',
'OCP\\Notification\\InvalidValueException' => $baseDir . '/lib/public/Notification/InvalidValueException.php',
'OCP\\Notification\\UnknownNotificationException' => $baseDir . '/lib/public/Notification/UnknownNotificationException.php',
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php',
'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php',
'OCP\\Notification\\IncompleteNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteNotificationException.php',
'OCP\\Notification\\IncompleteParsedNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteParsedNotificationException.php',
'OCP\\Notification\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Notification/InvalidValueException.php',
'OCP\\Notification\\UnknownNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/UnknownNotificationException.php',
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Notification/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Notification\IDismissableNotifier;
use OCP\Notification\IManager;
use OCP\Notification\IncompleteNotificationException;
use OCP\Notification\IncompleteParsedNotificationException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;
Expand Down Expand Up @@ -365,13 +366,14 @@ public function prepare(INotification $notification, string $languageCode): INot
}

if (!$notification->isValidParsed()) {
throw new \InvalidArgumentException('The given notification has not been handled');
$this->logger->info('Notification was claimed to be parsed, but was not fully parsed by ' . get_class($notifier) . ' [app: ' . $notification->getApp() . ', subject: ' . $notification->getSubject() . ']');
throw new IncompleteParsedNotificationException();
}
}

if (!$notification->isValidParsed()) {
$this->logger->info('Notification was not parsed by any notifier [app: ' . $notification->getApp() . ', subject: ' . $notification->getSubject() . ']');
throw new \InvalidArgumentException('The given notification has not been handled');
throw new IncompleteParsedNotificationException();
}

return $notification;
Expand Down
3 changes: 3 additions & 0 deletions lib/public/Notification/INotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ public function getName(): string;
* @return INotification
* @throws UnknownNotificationException When the notification was not prepared by a notifier
* @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
* @throws IncompleteParsedNotificationException Only to be thrown by the {@see IManager}
* @since 9.0.0
* @since 30.0.0 Notifiers should throw {@see UnknownNotificationException} instead of \InvalidArgumentException
* when they did not handle the notification. Throwing \InvalidArgumentException directly is deprecated and will
* be logged as an error in Nextcloud 39.
* @since 30.0.0 Throws {@see IncompleteParsedNotificationException} when not all required fields
* are set at the end of the manager or after a INotifier that claimed to have parsed the notification.
*/
public function prepare(INotification $notification, string $languageCode): INotification;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCP\Notification;

/**
* Thrown when {@see \OCP\Notification\IManager::prepare()} is called with a notification
* that does not have all required fields set at the end of the manager or after a INotifier
* that claimed to have parsed the notification.
*
* Required fields are:
*
* - app
* - user
* - dateTime
* - objectType
* - objectId
* - parsedSubject
*
* @since 30.0.0
*/
class IncompleteParsedNotificationException extends \InvalidArgumentException {
}