Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Refactor System.exit into return codes or exceptions #27

Closed
cyrille-artho opened this issue Jan 30, 2019 · 8 comments
Closed

Refactor System.exit into return codes or exceptions #27

cyrille-artho opened this issue Jan 30, 2019 · 8 comments

Comments

@cyrille-artho
Copy link
Owner

cyrille-artho commented Jan 30, 2019

For being able to use a unit-test framework on some system tests, failing configurations have to avoid exiting the VM. Therefore, it is essential that the use of System.exit is minimized.
This requires refactoring a lot of existing code:

  • main cannot have a return value, so a different function (e.g., run) should provide the same functionality with a return value instead of exit code. main continues to provide an exit code for system tests and production usage, calling run internally.
  • Any usage of System.exit should be rewritten such that, at the top level, run returns the status as an exit code, and only main actually exits.

As of now, there are 13 instances of System.exit in the code base.

cyrille-artho added a commit that referenced this issue Jan 31, 2019
	modified:   src/main/scala/modbat/mbt/Dotify.scala, src/main/scala/modbat/mbt/Main.scala, src/main/scala/modbat/mbt/Modbat.scala
cyrille-artho added a commit that referenced this issue Jan 31, 2019
…o return.

	modified:   config/src/main/scala/modbat/config/ConfigMgr.scala, src/main/scala/modbat/mbt/Main.scala
@cyrille-artho
Copy link
Owner Author

Refactored some uses in the commits shown above. 8 instances left.

cyrille-artho added a commit that referenced this issue Jan 31, 2019
	modified:   src/main/scala/modbat/mbt/Dotify.scala
@cyrille-artho cyrille-artho changed the title Refactor System.exit into return codes Refactor System.exit into return codes or exceptions Mar 4, 2019
@cyrille-artho
Copy link
Owner Author

For cases with deeply nested method calls, exceptions would be a better way of propagating error codes (as that would not require inserting "return" statements everywhere).

@cyrille-artho
Copy link
Owner Author

I'll review the earlier changes w.r.t. that and convert return statements to exceptions if appropriate, and will then move on to the forked repo.

@cyrille-artho
Copy link
Owner Author

Something was not done so well (my mistake...); check issue #45.

AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 13, 2019
…so in Main)

	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala
cyrille-artho pushed a commit that referenced this issue May 13, 2019
)

modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala
@AlexandreFournel
Copy link
Contributor

AlexandreFournel commented May 14, 2019

Existing changes to change again (to use exceptions):
14c1fe8

  • ConfigMgr.scala: main
  • ConfigMgr.scala: parseArgs incl. return type
  • Main.main: use of parseArgs

03899e8
Already modified.

24a882f

Remaining uses of System.exit

cyrille-artho pushed a commit that referenced this issue May 14, 2019
* Issue #27: change return code in Dotify to exception (also in Main)
	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala

* Line 45, I replaced return 1 by throw e in Main.scala
cyrille-artho pushed a commit that referenced this issue May 15, 2019
* Issue #27: change return code in Dotify to exception (also in Main)
	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala

* Line 45, I replaced return 1 by throw e in Main.scala

* in file MBT.scala, severals System.exit(1) replaced by throw(error)
cyrille-artho added a commit that referenced this issue May 15, 2019
	modified:   src/main/scala/modbat/mbt/Main.scala: Updated comment.
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 15, 2019
	new file:   src/main/java/modbat/mbt/NoTransitionException.java
	modified:   src/main/scala/modbat/mbt/MBT.scala
@cyrille-artho
Copy link
Owner Author

Return codes left: ConfigMgr.scala (both 0 and 1): replace "return 1" with exception, remove "return 0", and make "run" have no return parameters; Main.scala: replace "return 1" with exceptions.

@cyrille-artho
Copy link
Owner Author

cyrille-artho commented May 15, 2019

System.exit: a couple left; try:
find . -name '*.scala' | xargs grep 'System.exit'

cyrille-artho pushed a commit that referenced this issue May 15, 2019
* Issue #27: change return code in Dotify to exception (also in Main)

* Line 45, I replaced return 1 by throw e in Main.scala

* in file MBT.scala, several System.exit(1) replaced by throw(error)

* in file MBT.scala, System.exit changed by throw

	new file:   src/main/java/modbat/mbt/NoTransitionException.java
	modified:   src/main/scala/modbat/mbt/MBT.scala
	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala
cyrille-artho pushed a commit that referenced this issue May 19, 2019
* Issue #27: change return code in Dotify to exception (also in Main)
	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala

* Line 45, I replaced return 1 by throw e in Main.scala

* in file MBT.scala, severals System.exit(1) replaced by throw(error)

* in file MBT.scala, System.exit changed by throw

* Issue #27: change exit to exception.
	new file:   src/main/java/modbat/mbt/NoTransitionException.java
	modified:   src/main/scala/modbat/mbt/MBT.scala

* Remove return 1 replaced by throw exception.
cyrille-artho pushed a commit that referenced this issue May 20, 2019
…ala (#52)

* Issue #27: change return code in Dotify to exception (also in Main)
	modified:   src/main/scala/modbat/mbt/Dotify.scala
	modified:   src/main/scala/modbat/mbt/Main.scala

* in file MBT.scala, several System.exit(1) replaced by throw(error)

* in file MBT.scala, System.exit changed by throw

* Issue #27: change exit to exception.
	new file:   src/main/java/modbat/mbt/NoTransitionException.java
	modified:   src/main/scala/modbat/mbt/MBT.scala

* New changes - in MBT.scala, but also in ModbatTestHarness.scala

* New changes - no return 1 in ConfigMgr.scala, but now there are exceptions

* New changes  : add a try catch in ConfigMgr
@cyrille-artho
Copy link
Owner Author

Remaining open points:

  • Modbat.explore should not have return code
  • Main.run should not have return code
  • Main.main should not not use return code of run (perhaps pending in a current PR?)

AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 21, 2019
AlexandreFournel pushed a commit to AlexandreFournel/modbat that referenced this issue May 21, 2019
cyrille-artho pushed a commit that referenced this issue May 21, 2019
…48)

* Issue #27: change return code in Dotify to exception (also in Main)

* Line 45, I replaced return 1 by throw e in Main.scala

* in file MBT.scala, several System.exit(1) replaced by throw(error)

* in file MBT.scala, System.exit changed by throw

* Issue #27: change exit to exception.

* New changes  : add a try catch in ConfigMgr

* new changes, I don't really know if it's correct because the number of wrong tests has increased (due to the number with . which are not understood as number by ma MacOS

* Issue #27: remove return code in Main.run.

* Issue #27: remove return code in explore.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants