Skip to content

Commit f096402

Browse files
authored
Merge pull request #779 from patchlevel/improve-error-detected-exception
add first previous exception in error detected exception for better stack trace
2 parents 27d76fe + 6551d3c commit f096402

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/Subscription/Engine/ErrorDetected.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
use RuntimeException;
88

9-
use function array_map;
10-
use function implode;
9+
use function count;
1110
use function sprintf;
1211

1312
final class ErrorDetected extends RuntimeException
@@ -16,15 +15,14 @@ final class ErrorDetected extends RuntimeException
1615
public function __construct(
1716
public readonly array $errors,
1817
) {
19-
$sentences = array_map(
20-
static fn (Error $error) => sprintf(
21-
'Subscription %s: %s',
22-
$error->subscriptionId,
23-
$error->message,
18+
parent::__construct(
19+
sprintf(
20+
'%s error(s) in subscription engine detected. First error is in "%s" subscription: %s',
21+
count($errors),
22+
$errors[0]->subscriptionId,
23+
$errors[0]->message,
2424
),
25-
$errors,
25+
previous: $errors[0]->throwable,
2626
);
27-
28-
parent::__construct("Error in subscription engine detected.\n" . implode("\n", $sentences));
2927
}
3028
}

tests/Unit/Subscription/Engine/ErrorDetectedTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ public function testError(): void
2424

2525
self::assertSame($errors, $errorDetected->errors);
2626
self::assertSame(
27-
"Error in subscription engine detected.\nSubscription id1: error1\nSubscription id2: error2",
27+
'2 error(s) in subscription engine detected. First error is in "id1" subscription: error1',
2828
$errorDetected->getMessage(),
2929
);
30+
self::assertSame(
31+
$errors[0]->throwable,
32+
$errorDetected->getPrevious(),
33+
);
3034
}
3135
}

0 commit comments

Comments
 (0)