diff options
author | provokateurin <kate@provokateurin.de> | 2025-03-12 14:42:37 +0100 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2025-03-12 14:52:32 +0100 |
commit | 3c698c6553c5b22391aa300718c2dc1d3ebd2fe3 (patch) | |
tree | 4a0c6fad962567fbe26da9e00dc93c4ec86c7ff9 | |
parent | 7bcaefdaf744b8538329dcac915734f98b98aeaf (diff) | |
download | nextcloud-server-3c698c6553c5b22391aa300718c2dc1d3ebd2fe3.tar.gz nextcloud-server-3c698c6553c5b22391aa300718c2dc1d3ebd2fe3.zip |
fix(RichObjectStrings): Make exception messages for invalid parameters more useful for debuggingfix/rich-object-strings/better-exception-messages
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | lib/private/Activity/Event.php | 4 | ||||
-rw-r--r-- | lib/private/RichObjectStrings/Validator.php | 10 | ||||
-rw-r--r-- | tests/lib/RichObjectStrings/ValidatorTest.php | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index 810af5c0612..54274acea6b 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -34,7 +34,7 @@ class Event implements IEvent { protected $subjectParsed = ''; /** @var string */ protected $subjectRich = ''; - /** @var array */ + /** @var array<string, array<string, string>> */ protected $subjectRichParameters = []; /** @var string */ protected $message = ''; @@ -44,7 +44,7 @@ class Event implements IEvent { protected $messageParsed = ''; /** @var string */ protected $messageRich = ''; - /** @var array */ + /** @var array<string, array<string, string>> */ protected $messageRichParameters = []; /** @var string */ protected $objectType = ''; diff --git a/lib/private/RichObjectStrings/Validator.php b/lib/private/RichObjectStrings/Validator.php index f3d2ffd5723..adc4a8710f7 100644 --- a/lib/private/RichObjectStrings/Validator.php +++ b/lib/private/RichObjectStrings/Validator.php @@ -56,7 +56,7 @@ class Validator implements IValidator { throw new InvalidObjectExeption('Parameter is malformed'); } - $this->validateParameter($parameter); + $this->validateParameter($placeholder, $parameter); } } @@ -64,7 +64,7 @@ class Validator implements IValidator { * @param array $parameter * @throws InvalidObjectExeption */ - protected function validateParameter(array $parameter): void { + protected function validateParameter(string $placeholder, array $parameter): void { if (!isset($parameter['type'])) { throw new InvalidObjectExeption('Object type is undefined'); } @@ -74,15 +74,15 @@ class Validator implements IValidator { $missingKeys = array_diff($requiredParameters, array_keys($parameter)); if (!empty($missingKeys)) { - throw new InvalidObjectExeption('Object is invalid, missing keys:' . json_encode($missingKeys)); + throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, missing keys:' . json_encode($missingKeys)); } foreach ($parameter as $key => $value) { if (!is_string($key)) { - throw new InvalidObjectExeption('Object is invalid, key ' . $key . ' is not a string'); + throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string'); } if (!is_string($value)) { - throw new InvalidObjectExeption('Object is invalid, value ' . $value . ' is not a string'); + throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string'); } } } diff --git a/tests/lib/RichObjectStrings/ValidatorTest.php b/tests/lib/RichObjectStrings/ValidatorTest.php index c5ce1f04dad..c5f88394a33 100644 --- a/tests/lib/RichObjectStrings/ValidatorTest.php +++ b/tests/lib/RichObjectStrings/ValidatorTest.php @@ -39,7 +39,7 @@ class ValidatorTest extends TestCase { $this->expectException(InvalidObjectExeption::class); - $this->expectExceptionMessage('Object is invalid, value 123 is not a string'); + $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', @@ -49,7 +49,7 @@ class ValidatorTest extends TestCase { ], ]); - $this->expectExceptionMessage('Object is invalid, key 456 is not a string'); + $this->expectExceptionMessage('Object for placeholder string1 is invalid, key 456 is not a string'); $v->validate('test {string1} test.', [ 'string1' => [ 'type' => 'user', |