Skip to content

Replace System.exit with exception#1300

Merged
lemmy merged 2 commits intomasterfrom
mku-SystemExit
Feb 5, 2026
Merged

Replace System.exit with exception#1300
lemmy merged 2 commits intomasterfrom
mku-SystemExit

Conversation

@lemmy
Copy link
Member

@lemmy lemmy commented Feb 5, 2026

Replace System.exit(1) calls in XMLExporter and SANY to be used as a library where the caller can handle the exception instead of having the JVM terminated.

[Refactor][XMLExporter][SANY]

Replace `System.exit(1)` call when `sany.xsd` schema file is not found
with `XMLExportingException` containing `FileNotFoundException` as the
cause. This allows XMLExporter to be used as a library where the caller
can handle the exception instead of having the JVM terminated.

Also make the run() method public to provide a library-friendly API that
throws exceptions rather than calling System.exit.

The System.exit(1) call was introduced in PR #1054 (commit 6d0d6e4)
for one error case while similar error cases used exceptions, creating
an inconsistency in error handling.

[Refactor][XMLExporter]

Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
@lemmy lemmy added enhancement Lets change things for the better Tools The command line tools - TLC, SANY, ... labels Feb 5, 2026
@lemmy lemmy self-assigned this Feb 5, 2026
@lemmy lemmy requested a review from Copilot February 5, 2026 00:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors error handling in XMLExporter and SANY to replace System.exit() calls with exceptions, enabling these components to be used as libraries where callers can handle errors without JVM termination.

Changes:

  • Introduced new SANYExitException class to encapsulate exit codes and error messages
  • Modified SANY.java to create SANYmain0() method that throws SANYExitException instead of calling System.exit()
  • Modified XMLExporter.java to throw XMLExportingException instead of calling System.exit() when schema file is missing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tlatools/org.lamport.tlatools/src/tla2sany/drivers/SANYExitException.java New exception class to wrap exit codes and messages for library usage
tlatools/org.lamport.tlatools/src/tla2sany/drivers/SANY.java Added SANYmain0() that throws SANYExitException; SANYmain() wraps it for backward compatibility
tlatools/org.lamport.tlatools/src/tla2sany/xml/XMLExporter.java Made run() method public; replaced System.exit() with XMLExportingException for missing schema file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace `System.exit()` calls in SANY's command-line argument parsing
with `SANYExitException` thrown from a new `SANYmain0()` method. This
allows SANY to be used as a library where the caller can handle the
exception instead of having the JVM terminated.

The existing `SANYmain()` method now wraps `SANYmain0()` with a
try-catch that calls System.exit() to maintain backwards compatibility
for command-line usage.

This continues the refactoring started in the XMLExporter to eliminate
System.exit calls throughout the codebase, making components more
suitable for library usage.

[Refactor][SANY]

Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
@lemmy lemmy requested a review from Calvin-L February 5, 2026 01:09
@lemmy lemmy marked this pull request as ready for review February 5, 2026 01:09
@ahelwer
Copy link
Contributor

ahelwer commented Feb 5, 2026

Does this change the output of SANY when run at the command line so it ends with a stack trace?

@lemmy
Copy link
Member Author

lemmy commented Feb 5, 2026

Does this change the output of SANY when run at the command line so it ends with a stack trace?

No

@lemmy lemmy merged commit db727a7 into master Feb 5, 2026
9 checks passed
@lemmy lemmy deleted the mku-SystemExit branch February 5, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Lets change things for the better Tools The command line tools - TLC, SANY, ...

Development

Successfully merging this pull request may close these issues.

3 participants