symfony/http-kernel · error · InvalidArgumentException

Collector " " does not exist.

Error message

Collector "%s" does not exist.

What it means

Profiler::get() exposes the profiler's registered collectors by name and throws InvalidArgumentException if no collector with that name is registered. It is a thin array lookup over the collectors set up at profiler construction, so any unregistered name triggers the error.

Solutions

  1. Check existence first with $profiler->has($name) before calling get().
  2. Verify the collector service is registered and tagged 'data_collector' (or listed in framework.profiler config) for the current environment.
  3. Fix the collector name typo — the key equals the name used at registration.
  4. In tests, enable the collector in the test kernel configuration or assert with has().
  5. If the collector was removed in an upgrade, migrate calling code to the new collector name or API.

Example fix

// before
$collector = $profiler->get('twig');
// after
if ($profiler->has('twig')) {
    $collector = $profiler->get('twig');
} else {
    $collector = null; // collector not enabled in this environment
}
Defensive patterns

Strategy: type-guard

Validate before calling

if ($profiler->has('db')) {
    $dbCollector = $profiler->get('db');
}

Type guard

function getCollectorSafe(Profiler $profiler, string $name): ?DataCollectorInterface {
    return $profiler->has($name) ? $profiler->get($name) : null;
}

Try / catch

try {
    $collector = $profiler->get($name);
} catch (\InvalidArgumentException $e) {
    $collector = null; // not registered in this environment
}

Prevention

When it happens

Trigger: Calling $profiler->get('db') when the collector was never registered — collector disabled via config in the current environment, service removed in a bundle upgrade, collector only enabled in dev but accessed in prod, or a misspelled collector name.

Common situations: Code reading collectors directly (custom listeners, functional-test assertions) running where the collector is disabled; refactoring after a bundle renamed its collector service id; calling get() before any add() ran on a manually built Profiler.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/2b89c4e453a70f07. Report an issue: GitHub.

Appendix: source

Thrown at Profiler/Profiler.php:245

     *
     * @param string $name A collector name
     */
    public function has(string $name): bool
    {
        return isset($this->collectors[$name]);
    }

    /**
     * Gets a Collector by name.
     *
     * @param string $name A collector name
     *
     * @throws \InvalidArgumentException if the collector does not exist
     */
    public function get(string $name): DataCollectorInterface
    {
        if (!isset($this->collectors[$name])) {
            throw new \InvalidArgumentException(\sprintf('Collector "%s" does not exist.', $name));
        }

        return $this->collectors[$name];
    }

    private function getTimestamp(?string $value): ?int
    {
        if (null === $value || '' === $value) {
            return null;
        }

        try {
            $value = new \DateTimeImmutable(is_numeric($value) ? '@'.$value : $value);
        } catch (\Exception) {
            return null;
        }

        return $value->getTimestamp();

View on GitHub (pinned to aa3a39d728)