From 0a5d0099e59b78f7904c7c3c072cb4cb4f5a9f7d Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Fri, 9 Oct 2026 10:44:57 +0200 Subject: [PATCH] fix(task) #239 Fix PropertyGetterTask: catch any `\Throwable`, so that the `TypeError` of the property accessor on a scalar input is set on the state (with the `property` error context) and handled according to the task `error_strategy` instead of escaping it. Update documentation, add tests. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + docs/reference/tasks/property_getter_task.md | 4 ++-- src/Task/PropertyGetterTask.php | 2 +- tests/Task/PropertyGetterTaskTest.php | 10 ++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdf7f535..0dbf10c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Latest ## Fixes * [#143](https://github.com/cleverage/process-bundle/issues/143) Fix InputIteratorTask: an `\IteratorAggregate` input whose `getIterator()` does not return an `\Iterator` (e.g. another `\IteratorAggregate`) is iterated instead of failing with a `TypeError`. Update documentation, add tests. +* [#239](https://github.com/cleverage/process-bundle/issues/239) Fix PropertyGetterTask: catch any `\Throwable`, so that the `TypeError` of the property accessor on a scalar input is set on the state (with the `property` error context) and handled according to the task `error_strategy` instead of escaping it. Update documentation, add tests. v5.1 ----- diff --git a/docs/reference/tasks/property_getter_task.md b/docs/reference/tasks/property_getter_task.md index 1c15ecdf..a24ca1b4 100644 --- a/docs/reference/tasks/property_getter_task.md +++ b/docs/reference/tasks/property_getter_task.md @@ -21,8 +21,8 @@ Possible outputs `mixed`: the value read at the `property` path. -If the value cannot be read, the exception is set on the state (with the `property` added to the error context) and -handled according to the task `error_strategy`. +If the value cannot be read (including a `\TypeError` of the property accessor, e.g. on a scalar input), the exception +is set on the state (with the `property` added to the error context) and handled according to the task `error_strategy`. Options ------- diff --git a/src/Task/PropertyGetterTask.php b/src/Task/PropertyGetterTask.php index 10d97f85..b5e4c0e8 100644 --- a/src/Task/PropertyGetterTask.php +++ b/src/Task/PropertyGetterTask.php @@ -38,7 +38,7 @@ public function execute(ProcessState $state): void try { $output = $this->accessor->getValue($input, $property); - } catch (\Exception $e) { + } catch (\Throwable $e) { $state->addErrorContextValue('property', $property); $state->setException($e); diff --git a/tests/Task/PropertyGetterTaskTest.php b/tests/Task/PropertyGetterTaskTest.php index c8acb459..53a2a575 100644 --- a/tests/Task/PropertyGetterTaskTest.php +++ b/tests/Task/PropertyGetterTaskTest.php @@ -94,6 +94,16 @@ public function testPropertyPathOnArraySetsExceptionWithErrorContext(): void self::assertNull($state->getOutput()); } + public function testScalarInputSetsExceptionWithErrorContext(): void + { + // The PropertyAccessor throws a \TypeError (not an \Exception) on a scalar input + $state = $this->execute('[sku]', 'foo'); + + self::assertInstanceOf(\TypeError::class, $state->getException()); + self::assertSame(['property' => '[sku]'], $state->getErrorContext()); + self::assertNull($state->getOutput()); + } + public function testMissingPropertyOptionIsRejected(): void { $this->expectException(MissingOptionsException::class);