chapel-lang/chapel

Refactor mason error handling for better unit testing

Open

#28,120 opened on Dec 3, 2025

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Chapel (446 forks)auto 404
good first issuetype: Refactor

Repository metrics

Stars
 (2,010 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide