Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] InvalidCatch: WrappedExceptionsInterface #57667

Closed
@rela589n

Description

@rela589n

Description

Currently if anyone will try to catch WrappedExceptionsInterface, he will receive following psalm static analysis error:

ERROR: InvalidCatch
at /home/rela589n/Projects/opensource/phphd/exceptional-validation-bundle/Messenger/ExceptionalValidationMiddleware.php:31:9
Class/interface Symfony\Component\Messenger\Exception\WrappedExceptionsInterface cannot be caught (see https://psalm.dev/132)
        try {
            return $stack->next()->handle($envelope, $stack);
        } catch (WrappedExceptionsInterface $exception) {
            /** @var WrappedExceptionsInterface&Throwable $exception */

            $thrownException = new MessengerThrownException($exception);

It would make sense to make all exception interfaces extend Throwable in order to avoid this issue:

-interface WrappedExceptionsInterface
+interface WrappedExceptionsInterface extends \Throwable
{
    /**
     * @return \Throwable[]
     */
    public function getWrappedExceptions(?string $class = null, bool $recursive = false): array;
}

It's a minor enhancement, but it would still improve DX when working with Symfony

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions