hotwired / stimulus-rails

Use Stimulus in your Ruby on Rails app
https://stimulus.hotwired.dev
MIT License
637 stars 91 forks source link

Rethrow error when failing to register a controller #145

Closed stefannibrasil closed 2 months ago

stefannibrasil commented 2 months ago

Fixes https://github.com/hotwired/stimulus-rails/issues/102

When failing to register a controller, Stimulus catches the error and logs a console message. But that means the error won't be logged in a monitoring tool, making it hard to identify the issue.

This change follows the pattern in other files to catch this Type Error, format an error message, and re-throw the error so it can be tracked by monitoring tools.

This is my first contribution to Stimulus, so please let me know what I am missing. Thanks for reviewing it!

Before

Screenshot 2024-09-18 at 10 29 15 AM

After

Screenshot 2024-09-18 at 10 43 39 AM

PS. I noticed we don't have unit JS tests. Would setting something up for unit tests be a helpful future contribution?

dhh commented 2 months ago

Excellent fix! Like how it also prevents swallowing of any exceptions that might not be TypeErrors.

Yes, I'd be happy for us to explore a test suite for this stuff. If we can find a way to do it that isn't overly complicated!

stefannibrasil commented 2 months ago

Thank you for the feedback! I will explore some approaches for JS testing when I am back from RailsWorld 🎉