Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve message when is missing array resource for array fields #3713

Open
Paul-Bob opened this issue Mar 4, 2025 · 8 comments
Open

Improve message when is missing array resource for array fields #3713

Paul-Bob opened this issue Mar 4, 2025 · 8 comments
Assignees
Labels
Developer Experience (DX) Good first issue Good for newcomers Help wanted We could use some help with this

Comments

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Mar 4, 2025

Context

Improve the error message when a resource cannot be found for an array field.
field :items, as: :array

Current behavior:

Image

Enhancement:

  • Detect when the error is triggered from an array field.
  • Add the --array flag in the generator command.

Expected message:

... You may generate a resource for it by running 'rails generate avo:resource item --array'.

@Paul-Bob Paul-Bob moved this to To Do in Issues Mar 4, 2025
@Paul-Bob Paul-Bob added Good first issue Good for newcomers Help wanted We could use some help with this labels Mar 4, 2025
@adrianthedev adrianthedev moved this from To Do to Backlog in Issues Mar 5, 2025
@zhephyn
Copy link
Contributor

zhephyn commented Mar 7, 2025

Hey @Paul-Bob .
Is there a picture you could link to showing what the improved error message looks like?
I would love to give this issue a shot.
Could we perhaps use the better errors gem for this?

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Mar 7, 2025

Hi @zhephyn thanks for looking into this.

Is there a picture you could link to showing what the improved error message looks like?

I don’t have a screenshot of the improved error message for arrays yet, as it hasn’t been implemented. The only planned change is adding the --array flag to the generator command: "You may generate a resource for it by running 'rails generate avo:resource item --array'"

I would love to give this issue a shot.

That’s awesome, thank you! We appreciate your help.

Could we perhaps use the better errors gem for this?

The better_errors gem can certainly be used in the parent application, but we wouldn’t want to add it as an Avo dependency. Each project using Avo can decide independently whether to include better_errors.

@zhephyn
Copy link
Contributor

zhephyn commented Mar 7, 2025

Cool. I now understand what the enhancement requires me to implement.
Is there a way i can reproduce the above error(the one in the picture above) in my local avo repository?

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Mar 7, 2025

Yes @zhephyn

Is there a way i can reproduce the above error(the one in the picture above) in my local avo repository?

You can trigger this error by adding field :items, as: :array to any resource's fields and then visiting that resource's show page.

@zhephyn
Copy link
Contributor

zhephyn commented Mar 7, 2025

You can trigger this error by adding field :items, as: :array to any resource's fields and then visiting that resource's show page.

@Paul-Bob When i do the above, for example adding this line( field :items, as: :array) to the post.rb resource file, all i get when i navigate to the show page is a flash notice shown below instead of the error above.

There's an invalid field configuration for this resource.
field :items, as: :array

I already have a possible solution in mind however i can't tell whether it's feasible or not if i can't reproduce the error

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Mar 7, 2025

@zhephyn, could you share what the lib/avo/version.rb file looks like?

@zhephyn
Copy link
Contributor

zhephyn commented Mar 8, 2025

I'm done implementing this. Gonna refine the code and push a PR up shortly.

Image

@Paul-Bob
Copy link
Contributor Author

Paul-Bob commented Mar 8, 2025

Looking good @zhephyn!

I forgot to mention in the original scope, but let's also ensure that when the error raises on an array field, the documentation links to the array resources.

https://docs.avohq.io/3.0/array-resources.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience (DX) Good first issue Good for newcomers Help wanted We could use some help with this
Projects
Status: Backlog
Development

No branches or pull requests

2 participants