Skip to content

Purge and delete modules if after_compile/2 callback fails#15220

Merged
sabiwara merged 1 commit intoelixir-lang:mainfrom
sabiwara:purge-failed-after-compile
Mar 26, 2026
Merged

Purge and delete modules if after_compile/2 callback fails#15220
sabiwara merged 1 commit intoelixir-lang:mainfrom
sabiwara:purge-failed-after-compile

Conversation

@sabiwara
Copy link
Copy Markdown
Contributor

This probably doesn't have an impact in regular use cases, but it should fix the following gotcha in Livebook: livebook-dev/livebook#3162.

I'm not sure if I'm missing any case where we might want to keep a module for which the callback failed.

@sabiwara sabiwara force-pushed the purge-failed-after-compile branch from 9374cc6 to 026d7e7 Compare March 25, 2026 23:54
@zachdaniel
Copy link
Copy Markdown
Contributor

At some point it was explained to me that after_verify callbacks must not raise errors/crash. Does this make that not a problem anymore?

@sabiwara
Copy link
Copy Markdown
Contributor Author

I remember this was discussed at some point indeed... perhaps the issue is to fix ExUnit.Case then to raise at a different step?

@josevalim
Copy link
Copy Markdown
Member

I remember this was discussed at some point indeed... perhaps the issue is to fix ExUnit.Case then to raise at a different step?

Yes! Or make it warn.

@josevalim
Copy link
Copy Markdown
Member

Sorry, I just realized this is about __after_compile__, not __after_verify__. __after_verify__ cannot fail, because it runs at different moments, and after bytecode has been written to disk, but __after_compile__ arguably can as it always runs in a very specific scenario and it effectively aborts compilation.

@sabiwara sabiwara changed the title Purge and delete modules if after_verify/2 callback fails Purge and delete modules if after_compile/2 callback fails Mar 26, 2026
@sabiwara
Copy link
Copy Markdown
Contributor Author

Indeed I made a mistake in the description, apologies for the confusion.

I realized the same thing after going back to the @after_verfiy docs:

Furthermore, after verification callbacks are not expected to raise. Given they run after the code is compiled, artifacts have already been written to disk, and therefore raising does not effectively halt compilation and may leave unused artifacts on disk. If you must raise, use @after_compile or other callback.

@sabiwara sabiwara merged commit a58a40c into elixir-lang:main Mar 26, 2026
15 checks passed
@sabiwara sabiwara deleted the purge-failed-after-compile branch March 26, 2026 11:08
@sabiwara
Copy link
Copy Markdown
Contributor Author

Sorry I merged after renaming the PR, but the commit still got merged with the wrong commit message 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants