Skip to content

Give the service ids in the error on duplicate client codes #33

Closed

Description

@njoubert-cleverage

Description

Two clients with the same code (ClientInterface::getCode()) make every process using a REST task fail with Client <code> is already defined, when the registry is instantiated. The message does not tell which services are in conflict. Clients are usually declared with the same class (CleverAge\RestProcessBundle\Client\Client, configured by its constructor arguments), so they can only be found by searching every service tagged cleverage.rest.client.

Reproduction

In process-bundle-demo, declare a second client with the apicarto_ign code:

# config/services.yaml
services:
    app.cleverage_rest_process.client.apicarto_ign:
        class: CleverAge\RestProcessBundle\Client\Client
        bind:
            $code: 'apicarto_ign'
            $uri: 'https://apicarto.ign.fr/api'
        tags:
            - { name: cleverage.rest.client }
    app.cleverage_rest_process.client.apicarto_ign_duplicate:
        class: CleverAge\RestProcessBundle\Client\Client
        bind:
            $code: 'apicarto_ign'
            $uri: 'https://apicarto.ign.fr/api'
        tags:
            - { name: cleverage.rest.client }
$ bin/console cleverage:process:execute demo.rest.get
In ClientRegistry.php line 30:
  Client apicarto_ign is already defined

cache:clear, lint:container and the processes without REST task still work: the error only appears when a REST process runs.

Expected: Client apicarto_ign is already defined by service "app.cleverage_rest_process.client.apicarto_ign", cannot register service "app.cleverage_rest_process.client.apicarto_ign_duplicate".

Tested on main (daf62a9), cleverage/process-bundle 5.1, PHP 8.5, Symfony 7.4.

Proposed fix

Replace the generic RegistryCompilerPass by a compiler pass of the bundle giving the service id to ClientRegistry::addClient() (new optional $serviceId argument), and give both service ids in the exception message. Update reference/client.md.

Detecting the duplicates at compile time is out of scope: the code is only known once the client is instantiated, it would require declaring it as a tag attribute.

Same issue in cleverage/cache-process-bundle#25 and cleverage/soap-process-bundle#27 (fixed the same way).

Requirements

  • Documentation updates
    • Reference
    • Changelog
  • Unit tests

Breaking changes

None: the new argument of ClientRegistry::addClient() is optional, only the exception message changes.

Activity

  1. added a commit that references this issue on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions