28120, "jabraham17", "Refactor mason error handling for better unit testing", "2025-12-03T18:50:16Z"
Recently, while fixing an issue in mason I came across a rather frustrating problem when writing tests.
Mason uses exceptions to handle errors, but the following pattern shows up a lot
proc func() throws {
try! {
...
} catch e: MasonError {
exit(1);
}
}
func is marked throws, but will never throw. It will either catch a MasonError and exit or halt (due to the try!). This makes it hard to unit test func, since the thrown errors are never propagated out.
In #28119, I adjusted masonBuild so that it would not call exit or halt, and then in the top-level mason handler these thrown errors get turned into an exit or halt. This gives the same behavior for mason the executable, but makes unit testing masonBuild much easier.
I think we should apply similar transformations to other parts of the mason source, as a general software cleanup/refactor and as a way of improving the ability to test mason.