Phoenix server refuses to serve pages when there are pending migrations. That’s great! If it didn’t, it would often not really matter, often it would crash in an obvious way, but sometimes it would be difficult to realize what’s going on.
How can I have the same behaviour when assets fail to build? I always want to know if there’s an error in the javascript or CSS I’m playing with. Always. Otherwise I’m just debugging whatever previous version of the code I had working and I waste much time trying to figuring out why nothing works.
Perhaps a github issue is in order since this post got zero traction? It doesn’t look like there is a tenable way to make this happen without changing Phoenix itself (I could be wrong, though). I get burned by this often enough and would also love an option to upgrade these warnings to errors.
The problem here is that phoenix is completely unaware of what happens in the asset build pipeline. It just starts a process and that’s it. It can have a plug to check ecto migration status, because it can and knows how to talk to ecto. The same is not present for the assets pipeline. It’s also less likely to be added in phoenix itself given the assets pipeline is generally expected to be switched out easily.
The only “contract” assets pipelines have with phoenix is that they can be started as an external process (watchers) and that they eventually create/update files in /priv/static.
Interesting question! Looking at the esbuild docs you should be hook something up with your own esbuild plugin: esbuild - Plugins
Actually that’s an interesting little problem so I’ve created an example phoenix app that creates a little plugin that raises an error if there are currently any errors in the esbuild build:
It works by writing the build status to assets/esbuild_build_status and then a AssetStatusWeb.CheckAssetStatusPlug plug reads that in development mode, and if there are any errors the plug raises the errors. Here’s the commit that shows how it works: