Skip to content

Commit

Permalink
Exit process with error code if the operation fails
Browse files Browse the repository at this point in the history
When the license setting process failed, the process still returned with success (exit code = 0).
This made it more difficult to detect a problem: the caller process had to parse the output text of the process.

Exit code is now set to non-zero value, so the caller process can detect errors without searching for specific text patterns.
  • Loading branch information
lassoan committed Oct 24, 2023
1 parent 6500493 commit ed5be30
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion totalsegmentator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def setup_totalseg(totalseg_id=None):
def set_license_number(license_number):
if not is_valid_license(license_number):
print("ERROR: Invalid license number. Please check your license number or contact support.")
sys.exit(0)
sys.exit(1)

totalseg_dir = get_totalseg_dir()
totalseg_config_file = totalseg_dir / "config.json"
Expand Down
2 changes: 1 addition & 1 deletion totalsegmentator/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def download_model_with_license_and_unpack(task_name, config_dir):
else:
if r.json()['status'] == "invalid_license":
print(f"ERROR: Invalid license number ({license_number}). Please check your license number or contact support.")
sys.exit(0)
sys.exit(1)

except Exception as e:
raise e
Expand Down
6 changes: 3 additions & 3 deletions totalsegmentator/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def show_license_info():
For commercial usage contact: jakob.wasserthal@usb.ch
"""))
sys.exit(0)
sys.exit(1)
elif status == "invalid_license":
print(message)
sys.exit(0)
sys.exit(1)
elif status == "missing_config_file":
print(message)
sys.exit(0)
sys.exit(1)


def totalsegmentator(input, output, ml=False, nr_thr_resamp=1, nr_thr_saving=6,
Expand Down

0 comments on commit ed5be30

Please sign in to comment.