herbsjs / herbs

A domain-first framework. Code your domain and your infrastructure will follow
https://herbsjs.org/
MIT License
426 stars 14 forks source link

Hard to identify the reason of an error #22

Open eduardo-vortx opened 2 years ago

eduardo-vortx commented 2 years ago

Is your feature request related to a problem? Please describe.

Working on a project, I spent a good couple of hours strugling with a mistake I made.

In a scenario where a property of an entity is an array of another entity, like the image below:

image

And that entity is the response of my usecase:

image

If I push an object that isn't an entity (does not implements BaseEntity), it throws an error at runtime:

image

image

Describe the solution you'd like

It would be nice to have a better error message, telling the developer he is pushing the wrong object to that array. The example I created is very simple, so it's easier to identify the problem. But when I faced this problem, I was on a larger code base, so it took me a lot of time to understand what was going on.

Describe alternatives you've considered

Herbs is written in JS, so it's hard to handle this kind of errors because it only happens at runtime.

Thinking about the problem, may it would be possible to identify this by using Proxies on entity properties, so we can intercept the changes in the object and print a more specific message on the console.

Additional context

I created a minimal herbs project showing how to emulate the same problem.

jhomarolo commented 2 years ago

Hi @eduardo-vortx, thanks for your contribution.

Did you think about any solutions (in a tech way) for this issue yet?

italojs commented 2 years ago

Why not just fix the error? 🤷🏻‍♂️

italojs commented 2 years ago

@eduardo-vortx this issue stil alive?

jhomarolo commented 2 years ago

@italojs this issue is not about fixing the error. It is about showing us that it is hard to find the error.

jhomarolo commented 2 years ago

@eduardo-vortx did you tried to use herbs audit inside the env?