Skip to content

Commit

Permalink
Fix issue with GenericError from the inside of Task closure and updat…
Browse files Browse the repository at this point in the history
…e deps
  • Loading branch information
donhardman committed Jan 18, 2024
1 parent a8db5d1 commit 1af84b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
50 changes: 25 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ function (): void {
$this->result = $fn(...$argv);
} catch (Throwable $t) {
[$errorClass, $errorMessage] = [$t::class, $t->getMessage()];
$e = new GenericError("$errorClass: $errorMessage");
if ($errorMessage) {
$e->setResponseError($errorMessage);
if ($t instanceof GenericError) {
$e = $t;
} else {
$e = new GenericError("$errorClass: $errorMessage");
if ($errorMessage) {
$e->setResponseError($errorMessage);
}
}

$this->error = $e;
} finally {
$this->status = TaskStatus::Finished;
Expand Down
6 changes: 3 additions & 3 deletions test/BuddyCore/Task/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ function () use ($errorMessage): bool {
$this->assertEquals(TaskStatus::Finished, $task->getStatus());
$this->assertEquals(false, $task->isSucceed());
$error = $task->getError();
$this->assertEquals(true, $error instanceof GenericError);
$this->assertEquals(BuddyRequestError::class . ': ' . $errorMessage, $error->getMessage());
$this->assertEquals($errorMessage, $error->getResponseError());
$this->assertEquals(true, $error instanceof BuddyRequestError);
$this->assertEquals($errorMessage, $error->getMessage());
$this->assertEquals('Something went wrong', $error->getResponseError());
}

public function testTaskDeferredHasFLag(): void {
Expand Down

0 comments on commit 1af84b5

Please sign in to comment.