Skip to content

Commit

Permalink
minor #46671 [Workflow] Add a nice exception message when unexpected …
Browse files Browse the repository at this point in the history
…data is passed to Marking (Nyholm)

This PR was merged into the 6.2 branch.

Discussion
----------

[Workflow] Add a nice exception message when unexpected data is passed to Marking

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | n/a

During my Workshop during Symfony online, one of my attendees got an exception message they didn't really undersand.
They ran
```php
$this->workflow->apply($subject, 'foobar');
```
But got the error `Marking::__construct() expects array, string passed`.

Their issue was that `$subject->getPlaces()` returned a string. It was pretty hard to figure out from that exception message, so I thought we could improve.

Commits
-------

2e4bd96 [Workflow] Add a nice exception message when unexpected data is passed to Marking
  • Loading branch information
lyrixx committed Jun 17, 2022
2 parents 32600a3 + 2e4bd96 commit 3be9bfb
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function getMarking(object $subject): Marking

if ($this->singleState) {
$marking = [(string) $marking => 1];
} elseif (!is_array($marking)) {
throw new LogicException(sprintf('The method "%s::%s()" did not return an array and the Workflow\'s Marking store is instantiated with $singleState=false.', get_debug_type($subject), $method));
}

return new Marking($marking);
Expand Down

0 comments on commit 3be9bfb

Please sign in to comment.