Skip to content

Commit d2b0c40

Browse files
authored
Merge pull request #51445 from nextcloud/backport/51442/stable31
[stable31] fix(RichObjectStrings): Make exception messages for invalid parameters more useful for debugging
2 parents a59c89e + 4f27d82 commit d2b0c40

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/private/Activity/Event.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Event implements IEvent {
3434
protected $subjectParsed = '';
3535
/** @var string */
3636
protected $subjectRich = '';
37-
/** @var array */
37+
/** @var array<string, array<string, string>> */
3838
protected $subjectRichParameters = [];
3939
/** @var string */
4040
protected $message = '';
@@ -44,7 +44,7 @@ class Event implements IEvent {
4444
protected $messageParsed = '';
4545
/** @var string */
4646
protected $messageRich = '';
47-
/** @var array */
47+
/** @var array<string, array<string, string>> */
4848
protected $messageRichParameters = [];
4949
/** @var string */
5050
protected $objectType = '';

lib/private/RichObjectStrings/Validator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public function validate(string $subject, array $parameters): void {
5656
throw new InvalidObjectExeption('Parameter is malformed');
5757
}
5858

59-
$this->validateParameter($parameter);
59+
$this->validateParameter($placeholder, $parameter);
6060
}
6161
}
6262

6363
/**
6464
* @param array $parameter
6565
* @throws InvalidObjectExeption
6666
*/
67-
protected function validateParameter(array $parameter): void {
67+
protected function validateParameter(string $placeholder, array $parameter): void {
6868
if (!isset($parameter['type'])) {
6969
throw new InvalidObjectExeption('Object type is undefined');
7070
}
@@ -74,15 +74,15 @@ protected function validateParameter(array $parameter): void {
7474

7575
$missingKeys = array_diff($requiredParameters, array_keys($parameter));
7676
if (!empty($missingKeys)) {
77-
throw new InvalidObjectExeption('Object is invalid, missing keys:' . json_encode($missingKeys));
77+
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, missing keys:' . json_encode($missingKeys));
7878
}
7979

8080
foreach ($parameter as $key => $value) {
8181
if (!is_string($key)) {
82-
throw new InvalidObjectExeption('Object is invalid, key ' . $key . ' is not a string');
82+
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
8383
}
8484
if (!is_string($value)) {
85-
throw new InvalidObjectExeption('Object is invalid, value ' . $value . ' is not a string');
85+
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
8686
}
8787
}
8888
}

tests/lib/RichObjectStrings/ValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testValidate(): void {
3939

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

42-
$this->expectExceptionMessage('Object is invalid, value 123 is not a string');
42+
$this->expectExceptionMessage('Object for placeholder string1 is invalid, value 123 for key key is not a string');
4343
$v->validate('test {string1} test.', [
4444
'string1' => [
4545
'type' => 'user',
@@ -49,7 +49,7 @@ public function testValidate(): void {
4949
],
5050
]);
5151

52-
$this->expectExceptionMessage('Object is invalid, key 456 is not a string');
52+
$this->expectExceptionMessage('Object for placeholder string1 is invalid, key 456 is not a string');
5353
$v->validate('test {string1} test.', [
5454
'string1' => [
5555
'type' => 'user',

0 commit comments

Comments
 (0)