flarum/framework · error · InvalidArgumentException

Source type is not allowed for this collector. Allowed…

Error message

Source type %s is not allowed for this collector. Allowed types are: %s

What it means

Guard in SourceCollector::validateSourceType, run for every file/string/directory added to a frontend asset collector: if the collector was constructed with a restricted allowedSourceTypes list and the submitted SourceInterface implementation is not an instance of any allowed class/interface, the source cannot be compiled by this collector and an InvalidArgumentException is thrown naming the offending class and the allowed types.

Solutions

  1. Use the collector type intended for that source (e.g. Js vs Css collectors)
  2. Make the custom source implement/extend one of the collector's allowed source types
  3. Adjust the collector's allowedSourceTypes if you own the extension point
  4. Register the source with the correct Extend\Frontend extender
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at framework/core/src/Frontend/Compiler/Source/SourceCollector.php:84 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/49932fbcb36a8ecb. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Frontend/Compiler/Source/SourceCollector.php:84

    {
        return $this->sources;
    }

    protected function validateSourceType(SourceInterface $source): SourceInterface
    {
        // allowedSourceTypes is an array of class names (or interface names)
        // so we need to check if the $source is an instance of one of those classes/interfaces (could be a parent class as well)
        $isInstanceOfOneOfTheAllowedSourceTypes = false;

        foreach ($this->allowedSourceTypes as $allowedSourceType) {
            if ($source instanceof $allowedSourceType) {
                $isInstanceOfOneOfTheAllowedSourceTypes = true;
                break;
            }
        }

        if (! empty($this->allowedSourceTypes) && ! $isInstanceOfOneOfTheAllowedSourceTypes) {
            throw new \InvalidArgumentException(sprintf(
                'Source type %s is not allowed for this collector. Allowed types are: %s',
                $source::class,
                implode(', ', $this->allowedSourceTypes)
            ));
        }

        return $source;
    }
}

View on GitHub (pinned to 4b939f6853)