Skip to content

Do not create duplicate routes when running the action generator repeatedly#417

Merged
timriley merged 3 commits into
hanami:mainfrom
sandbergja:do-not-add-duplicate-routes
Jun 9, 2026
Merged

Do not create duplicate routes when running the action generator repeatedly#417
timriley merged 3 commits into
hanami:mainfrom
sandbergja:do-not-add-duplicate-routes

Conversation

@sandbergja

Copy link
Copy Markdown
Contributor

Closes #146

@sandbergja sandbergja marked this pull request as ready for review June 5, 2026 21:04
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

ℹ️ Optional job failed: Ruby jruby

@timriley

timriley commented Jun 8, 2026

Copy link
Copy Markdown
Member

Thanks for working on this, @sandbergja! ❤️

Just a thought on the approach: instead of raising RouteAlreadyExistsError in add_route_to_file and add_route_to_block (those are good and well-named new methods, btw!), how about we just turn it into a no-op, i.e. leave the routes file alone and continue execution?

My feeling is that if there really is a legitimate conflict, it would be on the action file itself, which we already handle noisily via the existing FileAlreadyExistsError.

Overall, I would like our generators just "do the right thing" as much as possible without erroring and forcing user reaction, and no-op-ing when a route already exists feels like it fits with this approach. What do you think?

(I also realised while reviewing this that we need to make our action generator aware of our new resource-based routing, and most likely prefer that by default. This is a whole separate piece of work, though! I'll make an issue for it: #418)

There's also a bunch of rubocop failures showing in the tests here, and that's because I changed one of our default rules last night. I'll go and fix that separately in the main branch now.

@timriley

timriley commented Jun 8, 2026

Copy link
Copy Markdown
Member

RuboCop issues fixed in abc244a, a rebase should sort you out here :)

@sandbergja sandbergja force-pushed the do-not-add-duplicate-routes branch from e5859b1 to eff36ba Compare June 8, 2026 03:18
@sandbergja

Copy link
Copy Markdown
Contributor Author

Sounds good to me, @timriley, and thanks for the review! I've rebased and changed the behavior to a no-op (with a short message informing the user that the route is being skipped).

@katafrakt

Copy link
Copy Markdown
Contributor

Just wanted to say: good job! I was trying to solve this issue once, but got stuck somewhere between Hanami CLI and Dry Files. You went into much better direction with the fix.

I also second that conflict should be o no-op, not a blocker - but you already fixed that.

@timriley

timriley commented Jun 9, 2026

Copy link
Copy Markdown
Member

Thank you again, @sandbergja, this is great! I just pushed up a changelog entry, and I'll merge this now :)

@timriley timriley merged commit 64870bc into hanami:main Jun 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action generator appends routes even if exists

3 participants