TLDR; if I want to modify the stimulus Application in an asset based rails project so it applies to ALL controllers, where do I do that?
I am working on a basic app that a) uses hotwire, b) does not touch Webpack.
This has been challenging and I’ve had to make compromises (like moving Tailwind compilation to its own project) but I’m really struggling with Sentry. After many hours I found this PR that explained a lot of what I was seeing, because Stimulus is overriding the default Sentry window.onerror.
Now I’m trying to figure out what to do about that. I found this bit about a global error handler (and other similar examples), but these all appear to be using the webpack method of stimulus - loading up via the index.js.
I also found this, which seemed like the correct choice for overriding the default handler to hook up to Sentry. But again, this is using the index.js / webpack method of loading stimulus.
(The index.js thing threw me for a while. I’m not sure why the stimulus:install puts that in there if its an asset pipeline project, since it doesn’t appear to be used. (unless I broke it somehow).)
But I can’t figure out where I would do the error handler override in an asset manager based project. Namely, I can’t figure out what loads the importmap controllers and how the app hooks them up, so I don’t know where to inject the code to override the error handler. I’ve tried all sorts of things and now I’m so tied up in Javascript knots I don’t know which way is up.
Note: I do NOT want to have to manually trap errors in my controllers in the global application controller method. To me, this kills the whole point of having Sentry and having it capture errors you completely missed or ones that happen due to unforeseen library conflicts. If I have to use a try / catch and call Sentry manually, I’ve already lost.