Skip to content

Undocumented error triggered when using Discovery with Symfony when php-http/httplug not installed #201

@asgrim

Description

@asgrim

I am using Psr18ClientDiscovery::find() in a library I'm writing, and I wrap the find() call in a try/catch to capture \Http\Discovery\Exception\NotFoundException. I used the library to do a manual test in a Symfony application, but instead of seeing any exception, I see the following E_USER_WARNING is raised:

User Warning: Got exception "LogicException (You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug".)" while checking if a PSR-18 Client is available

The message itself is fine, but I expect the library to throw a \Http\Discovery\Exception\NotFoundException, not trigger an error. I traced the change into the change #170 which catches the \LogicException thrown in Symfony, but instead of letting the exception bubble up, or wrapping it in a \Http\Discovery\Exception\NotFoundException, it converts it to a runtime error using trigger_error which was not expected or documented:

/**
* Finds a PSR-18 HTTP Client.
*
* @return ClientInterface
*
* @throws Exception\NotFoundException
*/
public static function find()

As a workaround, one can catch \ErrorException as well as \Http\Discovery\Exception\NotFoundException (or just catch \Throwable), but the fact remains that this is confusing and undocumented behaviour.

I think rather than converting the \LogicException into a trigger_error, the exception should be caught and converted to outwardly throw a NotFoundException, which is documented behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions