Skip to content

Commit 47f8858

Browse files
authored
fix: log constraint violation errors correctly (#550)
1 parent c5d8f74 commit 47f8858

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 10.4.3
2+
- Fixes an issue, where causes for validation errors were not logged correctly
3+
14
# 10.4.2
25
- Fixes an issue, where if an order was edited in the Administration, the payment amount could differ from the newly calculated total
36
- Fixes an issue, where accessing an uninitialized object during express checkout (shopware/SwagPayPal#512)

CHANGELOG_de-DE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# 10.4.3
2+
- Behebt ein Problem, bei dem Ursachen für Validierungsfehler nicht korrekt protokolliert wurden
3+
14
# 10.4.2
2-
- Behebt ein Problem, bei dem nach Bestelländerungen in der Administration Zahlungs- und Bestellsumme voneinander abweichen konnten.
5+
- Behebt ein Problem, bei dem nach Bestelländerungen in der Administration Zahlungs- und Bestellsumme voneinander abweichen konnten
36
- Behebt ein Problem, bei dem im PayPal Express Checkout der Zugriff auf ein nicht initialisiertes Objekt erfolgte (shopware/SwagPayPal#521)
47
- Behebt ein Problem, bei dem der HTTP-Cache durch das Erstellen einer Sitzung unnötig gestört wurde (shopware/SwagPayPal#529)
58

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "swag/paypal",
33
"description": "PayPal integration for Shopware 6",
4-
"version": "10.4.2",
4+
"version": "10.4.3",
55
"type": "shopware-platform-plugin",
66
"license": "MIT",
77
"authors": [

src/Util/IntrospectionProcessor.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Shopware\Core\Framework\HttpException;
1616
use Shopware\Core\Framework\Log\Package;
1717
use Shopware\Core\Framework\ShopwareHttpException;
18+
use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException;
1819
use Shopware\PayPalSDK\Contract\Gateway\GatewayInterface;
1920
use Swag\PayPal\Pos\Api\Exception\PosException;
2021
use Swag\PayPal\Pos\Client\AbstractClient as PosAbstractClient;
@@ -149,21 +150,27 @@ protected function getBacktrace(): array
149150
*/
150151
private function exceptionToContext(\Throwable $exception): array
151152
{
152-
$context = [
153-
'message' => $exception->getMessage(),
154-
'class' => $this->traceToClassString($exception->getTrace()[0]),
155-
'file' => $exception->getFile(),
156-
'line' => $exception->getLine(),
157-
];
153+
$context = ['message' => $exception->getMessage()];
158154

159155
if ($exception instanceof ShopwareHttpException) {
160156
$context['parameters'] = $exception->getParameters();
161157
}
162158

159+
if ($exception instanceof ConstraintViolationException) {
160+
foreach ($exception->getViolations() as $violation) {
161+
$context['parameters']['violations'][] = (string) $violation;
162+
}
163+
}
164+
163165
if ($exception instanceof HttpException || $exception instanceof PosException) {
164166
$context['errorCode'] = $exception->getErrorCode();
165167
}
166168

169+
// Order class, file and line at the end to make the exception & the most important information more readable in logs
170+
$context['class'] = $this->traceToClassString($exception->getTrace()[0]);
171+
$context['file'] = $exception->getFile();
172+
$context['line'] = $exception->getLine();
173+
167174
if ($exception->getPrevious()) {
168175
$context['previous'] = $this->exceptionToContext($exception->getPrevious());
169176
}

tests/Util/IntrospectionProcessorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Attributes\DataProvider;
1515
use PHPUnit\Framework\TestCase;
1616
use Shopware\Core\Framework\Log\Package;
17+
use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException;
1718
use Shopware\Core\Kernel;
1819
use Shopware\PayPalSDK\Gateway\OrderGateway;
1920
use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler;
@@ -23,6 +24,8 @@
2324
use Swag\PayPal\RestApi\V2\Resource\OrderResource;
2425
use Swag\PayPal\Storefront\Controller\PayPalController;
2526
use Swag\PayPal\Util\IntrospectionProcessor;
27+
use Symfony\Component\Validator\ConstraintViolation;
28+
use Symfony\Component\Validator\ConstraintViolationList;
2629

2730
/**
2831
* @internal
@@ -274,5 +277,23 @@ public static function invokeWithExceptionDataProvider(): \Generator
274277
'errorCode' => 'SWAG_PAYPAL__POS_EXCEPTION',
275278
]],
276279
];
280+
281+
yield 'ConstraintViolationException' => [
282+
['exception' => new ConstraintViolationException(new ConstraintViolationList([new ConstraintViolation(
283+
'test message',
284+
'test message template with {{ type }}',
285+
['{{ type }}' => 'testParameter'],
286+
'/root',
287+
'testProperty',
288+
'VIOLATION_TESTPROPERTY_INVALID'
289+
)]), [])],
290+
['exception' => [
291+
'message' => 'Caught 1 violation errors.',
292+
'parameters' => [
293+
'count' => 1,
294+
'violations' => ["/root.testProperty:\n test message"],
295+
],
296+
]],
297+
];
277298
}
278299
}

0 commit comments

Comments
 (0)