Skip to content

[Bug] All exceptions are caught for optional dependencies #32

@viktorprogger

Description

@viktorprogger

What steps will reproduce the problem?

Having the sample code:

class A
{
    public function __construct()
    {
        throw new RuntimeException('Something happened on initialization');
    }
}

class B
{
    public function __construct(private ?A $a = null)
    {
    }
}

$container->get(B::class);

What is the expected result?

The exception is thrown

What do you get instead?

Instance of B with a wrong dependency, and no exception is thrown. It' a hell to debug this situation.

Additional info

This code is responsible for the specified behavior. I'm pretty sure container definitions must not have a deal with application-level exceptions. In my opinion in the case when a dependency has a definition, and an exception is thrown on its resolving, this exception must not be catched by container/definition resolver, and doesn't matter if this dependency is optional or not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions