diff --git a/CHANGELOG.md b/CHANGELOG.md index 206837d5..3828793f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,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. * [#143](https://github.com/cleverage/process-bundle/issues/143) Fix level 8 edge cases failing with a `TypeError` or an `Error`: `CsvResource` rejects a blank header line and checks `ftell()`, XpathEvaluatorTransformer throws an explicit `\UnexpectedValueException` on an invalid query (with the libxml messages), a namespace node to unwrap or a node without document, SlugifyTransformer on a value that cannot be transliterated, `ProcessState::getContext()` returns `[]` until the context is defined, GenericTransformer and TransformerTrait throw a `\LogicException` when not initialized, IterableBatchTask and JsonStreamReaderTask can be flushed / iterated before their first execution, RegistryCompilerPass checks its configuration, SubprocessInstance checks the PHP executable. 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);