Skip to content
Merged
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
6 changes: 2 additions & 4 deletions lib/private/RichObjectStrings/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
* Class Validator
Expand Down Expand Up @@ -81,10 +79,10 @@ protected function validateParameter(string $placeholder, array $parameter): voi

foreach ($parameter as $key => $value) {
if (!is_string($key)) {
Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we on line 59 add mire context to the exception?
E.g. log the subject? Otherwise finding the origin is quite hard.

Copy link
Member Author

Choose a reason for hiding this comment

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

Notifications is handling this properly already, catching the exception and logging an app+subject message instead:

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

Copy link
Member Author

@nickvergessen nickvergessen Apr 9, 2025

Choose a reason for hiding this comment

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

}
if (!is_string($value)) {
Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/RichObjectStrings/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\RichObjectStrings\Validator;
use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption;
use Test\TestCase;

class ValidatorTest extends TestCase {
Expand All @@ -36,6 +37,9 @@ public function testValidate(): void {
]);
$this->addToAssertionCount(2);

$this->expectException(InvalidObjectExeption::class);

$this->expectExceptionMessage('Object for placeholder string1 is invalid, value 123 for key key is not a string');
$v->validate('test {string1} test.', [
'string1' => [
'type' => 'user',
Expand All @@ -45,6 +49,7 @@ public function testValidate(): void {
],
]);

$this->expectExceptionMessage('Object for placeholder string1 is invalid, key 456 is not a string');
$v->validate('test {string1} test.', [
'string1' => [
'type' => 'user',
Expand Down
Loading