Skip to content

Commit

Permalink
Add mapping of nextRetryDelay field from ApplicationFailure to Applic…
Browse files Browse the repository at this point in the history
…ationFailureInfo
  • Loading branch information
roxblnfk committed Sep 24, 2024
1 parent bfacaf4 commit 613a0c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Exception/Failure/FailureConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static function mapExceptionToFailure(\Throwable $e, DataConverterInterfa
}

$failure->setApplicationFailureInfo($info);
$info->setNextRetryDelay(DateInterval::toDuration($e->getNextRetryDelay()));

Check failure on line 95 in src/Exception/Failure/FailureConverter.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)

PossiblyNullArgument

src/Exception/Failure/FailureConverter.php:95:42: PossiblyNullArgument: Argument 1 of Temporal\Api\Failure\V1\ApplicationFailureInfo::setNextRetryDelay cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 95 in src/Exception/Failure/FailureConverter.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)

PossiblyNullArgument

src/Exception/Failure/FailureConverter.php:95:42: PossiblyNullArgument: Argument 1 of Temporal\Api\Failure\V1\ApplicationFailureInfo::setNextRetryDelay cannot be null, possibly null value provided (see https://psalm.dev/078)
break;

case $e instanceof TimeoutFailure:
Expand Down
31 changes: 27 additions & 4 deletions tests/Unit/Exception/FailureConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Temporal\Tests\Unit\Exception;

use Carbon\CarbonInterval;
use Exception;
use Google\Protobuf\Duration;
use Temporal\Api\Failure\V1\Failure;
use Temporal\DataConverter\DataConverter;
use Temporal\DataConverter\EncodedCollection;
use Temporal\DataConverter\EncodedValues;
use Temporal\Exception\Failure\ApplicationFailure;
use Temporal\Exception\Failure\FailureConverter;
use Temporal\Internal\Support\DateInterval;
use Temporal\Tests\Unit\AbstractUnit;

final class FailureConverterTestCase extends AbstractUnit
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testStackTraceStringForAdditionalContextEvenWhenClassIsNotPresen

try {
$trace = FailureConverter::mapExceptionToFailure(
call_user_func(fn () => new Exception()),
call_user_func(fn() => new Exception()),
DataConverter::createDefault(),
)->getStackTrace();
} finally {
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testStackTraceStringWithoutExceptionArgs(): void
public function testMapFailureToException(): void
{
$converter = DataConverter::createDefault();
$failure = new \Temporal\Api\Failure\V1\Failure();
$failure = new Failure();
$failure->setApplicationFailureInfo($info = new \Temporal\Api\Failure\V1\ApplicationFailureInfo());
$failure->setStackTrace("test stack trace:\n#1\n#2\n#3");
// Populate the info
Expand All @@ -132,4 +132,27 @@ public function testMapFailureToException(): void
$this->assertTrue($exception->hasOriginalStackTrace());
$this->assertSame("test stack trace:\n#1\n#2\n#3", $exception->getOriginalStackTrace());
}

public function testMapExceptionToFailure(): void
{
$converter = DataConverter::createDefault();
$exception = new ApplicationFailure(
'message',
'type',
true,
EncodedValues::fromValues(['foo', 'bar'], $converter),
nextRetryDelay: CarbonInterval::fromString('5 minutes 13 seconds 15 microseconds'),
);

$failure = FailureConverter::mapExceptionToFailure($exception, $converter);

$this->assertSame('type', $failure->getApplicationFailureInfo()->getType());
$this->assertTrue($failure->getApplicationFailureInfo()->getNonRetryable());
$this->assertSame(['foo', 'bar'], EncodedValues::fromPayloads(
$failure->getApplicationFailureInfo()->getDetails(),
$converter,
)->getValues());
$this->assertSame(5 * 60 + 13, $failure->getApplicationFailureInfo()->getNextRetryDelay()->getSeconds());
$this->assertSame(15_000, $failure->getApplicationFailureInfo()->getNextRetryDelay()->getNanos());
}
}

0 comments on commit 613a0c2

Please sign in to comment.