chapel-lang/chapel

Refactor mason error handling for better unit testing

Open

#28.120 aperta il 3 dic 2025

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Chapel (446 fork)auto 404
good first issuetype: Refactor

Metriche repository

Star
 (2010 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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.

Guida contributor