Skip to content

Conversation

@matthewsinclair
Copy link
Contributor

@matthewsinclair matthewsinclair commented Oct 23, 2025

Running mix format at umbrella root crashes with a MatchError in Mix.ProjectStack.

The Problem

The fix for #228 (commits 9eddbeb and 0d1048a) added compilation before formatting
to ensure modules are available. This breaks umbrella projects because calling
Mix.Task.run("compile") from within a formatter plugin triggers recursive
compilation, violating Mix.ProjectStack's expectations.

Changes

  • Added safe_compile/0 that checks Mix.Project.umbrella?() before compiling
  • Skips compilation at umbrella root, runs normally elsewhere
  • Added graceful error handling when modules can't be loaded
  • Improved error messages in the mix task for umbrella users
  • Added test coverage

Fixes #231

Skips compilation at umbrella root to avoid Mix.ProjectStack violations.
The compile task added in 9eddbeb (fixing ash-project#228) causes crashes in umbrella
projects because Mix.ProjectStack doesn't support recursive compilation
during format operations.
@zachdaniel
Copy link
Contributor

I've added some more logic here, mind pulling and updating? Thank you for the fix 🙇

@matthewsinclair
Copy link
Contributor Author

Thanks, Zach. LGTM for the merge.

@zachdaniel
Copy link
Contributor

Not sure if I messed it up again but there are still conflicts 😢

@matthewsinclair
Copy link
Contributor Author

matthewsinclair commented Oct 26, 2025

Not sure what the issue is? When I run the tests on my side on the PR branch in my fork, I get clean tests:

$ git status
On branch fix/umbrella-format-crash
Your branch is up to date with 'origin/fix/umbrella-format-crash'.

nothing to commit, working tree clean
$ mix test
Generated spark app
Running ExUnit with seed: 815428, max_cases: 32

..................................................................................................
Finished in 3.6 seconds (0.4s async, 3.1s sync)
5 doctests, 93 tests, 0 failures

What conflicts are you seeing? Or are you referring to the merge conflict below on lib/spark/formatter.ex?

Let me see if I can fix it on my side ... ok, should be good go now.

Resolved conflict in lib/spark/formatter.ex by updating safe_compile()
to include the loadpaths tasks from main (v2.3.11) while preserving
the umbrella project safety check.

This combines:
- The umbrella crash fix (skips compilation in umbrella projects)
- The loadpaths fix from v2.3.11
@zachdaniel
Copy link
Contributor

Please fix credo then I'll merge 🙇

@matthewsinclair
Copy link
Contributor Author

Done.

@zachdaniel
Copy link
Contributor

Actually...I was just about to merge this when I had a thought that this would be a pretty jarring experience for folks using this, because not being able to run mix format from the root. I assume you have an umbrella app here that hits this. Seems like what we should do is put this plugin in the .formatter.exs of those child projects? Would that potentially solve this?

@matthewsinclair
Copy link
Contributor Author

not run mix format from root

But that isn't how it works, or at least that's not how my fork works as far as I know. I am using my fork of this, and it works fine from the root of an umbrella project. It just checks to stop the recursion. But now you've got me worried that my fork and the mainline have diverged.

@zachdaniel
Copy link
Contributor

Oh, nvm. You're good.

@zachdaniel zachdaniel merged commit e5af5db into ash-project:main Oct 30, 2025
23 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.

mix format crashes at umbrella root with MatchError

2 participants