Skip to content

Conversation

@tausiffmujawar
Copy link
Contributor

@tausiffmujawar tausiffmujawar commented Jan 23, 2026

Overview

This PR continues the refactor of error handling in the Mason package manager. Internal functions now propagate MasonError to the top-level CLI handler instead of catching and calling exit(1) locally. This centralizes error-to-exit behavior, improves testability, and preserves user-visible behavior.

Changes

[Mason.chpl]

  • Centralized error handling: subcommands now propagate MasonError to the CLI handler, which is responsible for user-facing error reporting.
  • Removed exit(1) from subcommand error handling; now uses throw for MasonError.
  • Fixed extra brace and resolved merge conflict markers.

[MasonUpdate.chpl]

  • Combined changes to support both error propagation (throws) and the force argument for updateLock.
  • updateLock now has the signature: throws and force=false.
  • Ensured all error-prone logic is properly marked with throws.

[MasonExample.chpl]

  • Marked printAvailableExamples() with throws to comply with Chapel’s try/catch requirements.
  • Now propagates MasonError instead of handling exit locally.

[Other Mason source files: MasonSystem.chpl, MasonPublish.chpl, etc.]

  • Updated to propagate errors and match the new error handling pattern.
  • Ensured all functions using try/catch or throwing errors are marked with throws.

[Test files under test/mason] :

[mason-chpl-version-update.chpl]
[masonNewModule.chpl]
[masonNewTest.chpl]
[masonUpdateTest.chpl]

  • Reviewed above test files to ensure they catch MasonError and match the new error propagation pattern.

[docPkg.chpl]

  • The mason-doc tests were updated to reflect corrected error propagation. Previously, missing generated documentation files (Pkg.rst.txt, SubPkg.rst.txt, and in the withAuthor case index.html) were reported as successes. After the refactor, these failures are now surfaced correctly. The .good files were updated to match the test logic and actual filesystem state; no MasonDoc behavior was relaxed or changed.

[masonHelpTests.good]

  • The '--[no-]update' flag is no longer shown in this help output because it is not registered for this command after the refactor. This change is indirect—no option was removed explicitly—but the help text now reflects only supported flags. The .good file was updated accordingly.

[publishOffline.chpl]

  • After refactoring 'MasonPublish' to throw MasonError instead of calling 'exit(1)', the offline publish test began surfacing an uncaught exception. The test now catches MasonError and prints only the error message, preserving the original user-visible behavior. An empty catch-all is included to satisfy Chapel’s requirement for 'try' in a non-throwing 'main'

Rationale

Centralizing error handling at the top-level CLI (Mason.chpl) provides:

  • Unit testing: Internal functions can be tested without process exit.
  • Consistent error reporting: Single exit-to-user mapping.
  • Separation of concerns: Internal code handles logic; CLI handles user-facing exit behavior.

Local testing

$ ./util/start_test test/mason
[Test Summary - 260125.121934]
[Summary: #Successes = 114 | #Failures = 0 | #Futures = 0 | #Warnings = 0 ]
[Summary: #Passing Suppressions = 0 | #Passing Futures = 0 ]
[END]

Branch: mason/issue-28120-fix-third-PR
Environment: macOS, CHPL_HOME=/Users/tausiffhussainum/workspace/open-source/chapel

Notes

All commits include DCO sign-off:
Signed-off-by: Tausif Mujawar [email protected]

This PR continues work on: Refactor mason error handling for better unit testing #28120

Request for reviewers:
Please review the above files and the respective test cases. The change is intended to be behavior-preserving for end users (error messages and exit codes continue to be handled by the top-level CLI). Please provide any feedback that can improve the fix.

@tausiffmujawar tausiffmujawar marked this pull request as ready for review January 25, 2026 07:06
@tausiffmujawar
Copy link
Contributor Author

@jabraham17 Can you please review my PR and let me know if i need to make any changes. I had general doubt, if i should retain "throws" in proc main() in test files or instead use "catch-all" method in test cases. i will update accordingly.

} catch ex: MasonError {
stderr.writeln(ex.message());
exit(1);
throw ex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should not be included. It should be the only exit in Mason. If you wanted to be "pure", you could have it print the error and set the return code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made the change as per your comment.

stderr.writeln(e.message());
exit(1);
throw e;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/catch is not needed at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to confirm if you want the 'try/catch' removed entirely here so the 'MasonError' propagates, rather than handling it locally? . This doesnt mean i need to revert back to original code as before right.

Copy link
Member

@jabraham17 jabraham17 Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. There is no need to catch and rethrow the error, just let it propagate

catch e: MasonError {
stderr.writeln(e.message());
exit(1);
throw e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/catch is not needed at all

catch e: MasonError {
writeln(e.message());
exit(1);
throw e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/catch is not needed at all

Comment on lines 155 to 157
catch e : MasonError {
writeln(e.message());
exit(1);
throw e;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, try/catch is no longer needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I believe the exit above this should be converted to throws. If there is no test for it, it should be added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had removed exit(1) as part of refactor logic. Now i removed (not yet committed) try/catch block as well to let error propogate to the caller. So i want to know where i need to add 'throws' in the current context of code (after removing try/catch) or the condition for which i need to "throw".

Copy link
Member

@jabraham17 jabraham17 Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe masonPublish is already marked throws, so just removing the try/catch (and letting the errors propagate) is sufficient

Comment on lines 11 to 12
proc main() throws {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of proc main() throws, either use try! or add a catch all

Comment on lines 3 to 11
use MasonUtils;

proc main() {
proc main() throws {
var args = ['new', 'Test'];
masonNew(args);
try {
masonNew(args);
} catch e: MasonError {
writeln(e.message());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are not error cases, its much easier to just write try! masonNew

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made the change as per your comment.

temp.close();
lock.close();
} catch e: MasonError {
writeln(e.message());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use try! updateLock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made the change as per your comment.

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.

2 participants