shopware / shopware

Shopware 6 is an open commerce platform based on Symfony Framework and Vue and supported by a worldwide community and more than 1.500 community extensions
https://shopware.com
MIT License
2.76k stars 1.01k forks source link

If you mix up Definition and Entity the error can be improved #2341

Open Schrank opened 2 years ago

Schrank commented 2 years ago

Please describe the feature you would like to see implemented.

I just mixed up my Entity and my Definition, by writing:

<service id="WinkelwagenEvents\Entities\Slot\SlotExtensionEntity"> // HERE!! should be definition.
    <tag name="shopware.entity.definition" entity="winkelwagen_entities_slot"/>
</service>

The error thrown is:

Attempted to call an undefined method named "getEntityName" of class "WinkelwagenEvents\Entities\Slot\SlotExtensionEntity".
  1. The code in https://github.com/shopware/platform/blob/trunk/src/Core/Framework/DependencyInjection/CompilerPass/EntityCompilerPass.php#L51 should check wether $instance instanceof \Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition
  2. If not it should throw an error like "Did you mix up entitiy and definition for your entity" to improve developer experience and for easier debugging
RafaelKr commented 8 months ago

I forgot to specify the entity attribute on my tag.

This leads to an Definition * for entity does not exist error. Probably it would also be possible to catch this and tell the user that the entity attribute is missing.

Edit: Also I had a wrong entity name in my Definition (copy-paste error). I think that was the actual cause.

nisansei commented 3 months ago

I also ran into the Definition for entity * does not exist. issue when adding translations. In my case, the issue was that I was returning the Entity class instead of the Definition class in the translation definition.

I was doing:

    public function getParentDefinitionClass(): string
    {
        return YourEntityEntity::class; // Should be YourEntityDefinition::class
    }
MarcelSchmaeing commented 1 month ago

Hi,

thx for your issue we will put it into our new evaluation process and have a look at it again.

shopwareBot commented 1 month ago

[public] Automated response: This issue is linked to the internal issue https://shopware.atlassian.net/browse/NEXT-37887.

[created from NEXT-37887, comment 488635]