Skip to content

Commit 1211ae1

Browse files
cweiskeNamelessCoder
authored andcommitted
[FEATURE] Relay original exception in abstract record resource view helper
.. so we have a way to find out where the original error happened
1 parent 3896534 commit 1211ae1

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Classes/Utility/ErrorUtility.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
*/
1818
class ErrorUtility
1919
{
20-
public static function throwViewHelperException(?string $message = null, ?int $code = null): void
21-
{
22-
throw new Exception((string) $message, (integer) $code);
20+
public static function throwViewHelperException(
21+
?string $message = null,
22+
?int $code = null,
23+
?\Throwable $previous = null
24+
): void {
25+
throw new Exception((string) $message, (integer) $code, $previous);
2326
}
2427
}

Classes/ViewHelpers/Resource/Record/AbstractRecordResourceViewHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function render()
211211
// thrown by the getResources() method in subclasses are not
212212
// extended from a shared base class like RuntimeException. Thus,
213213
// we are forced to "catch them all" - but we also output them.
214-
ErrorUtility::throwViewHelperException($error->getMessage(), $error->getCode());
214+
ErrorUtility::throwViewHelperException($error->getMessage(), $error->getCode(), $error);
215215
}
216216
return $content;
217217
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace FluidTYPO3\Vhs\Utility;
3+
4+
/*
5+
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6+
*
7+
* For the full copyright and license information, please read the
8+
* LICENSE.md file that was distributed with this source code.
9+
*/
10+
11+
use FluidTYPO3\Vhs\Tests\Unit\AbstractTestCase;
12+
use FluidTYPO3\Vhs\Utility\ErrorUtility;
13+
14+
class ErrorUtilityTest extends AbstractTestCase
15+
{
16+
/**
17+
* @test
18+
*/
19+
public function transfersPreviousException()
20+
{
21+
try {
22+
$previous = new \Exception('a', 23);
23+
ErrorUtility::throwViewHelperException('b', 42, $previous);
24+
} catch (\Exception $exception) {
25+
$this->assertEquals('b', $exception->getMessage());
26+
$this->assertEquals(42, $exception->getCode());
27+
28+
$this->assertEquals('a', $exception->getPrevious()->getMessage());
29+
$this->assertEquals(23, $exception->getPrevious()->getCode());
30+
31+
return;
32+
}
33+
$this->fail('No exception thrown');
34+
}
35+
}

0 commit comments

Comments
 (0)