From 9ba0d7a67e42c5f0c5b6c396427365a8467ec7e7 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Mon, 14 Oct 2019 18:01:29 +0100 Subject: [PATCH] Provide better error codes --- twincat_version_manager.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/twincat_version_manager.py b/twincat_version_manager.py index 58d9f07..3483331 100644 --- a/twincat_version_manager.py +++ b/twincat_version_manager.py @@ -16,7 +16,7 @@ def check_versions(): for file_path, version_attrib in VERSION_TAGS.items(): found_files = glob.glob(file_path, recursive=True) if not found_files: - print("ERROR: No files of type {} found".format(file_path)) + raise IOError("ERROR: No files of type {} found".format(file_path)) for file in found_files: tree = ET.parse(file) try: @@ -29,7 +29,12 @@ def check_versions(): if __name__ == "__main__": - incorrect_files = check_versions() - for file, version in incorrect_files.items(): - print("ERROR: {} has incorrect version {}, expected version {}".format(file, version, CORRECT_VERSION)) - exit(len(incorrect_files)) # Exit with non-zero if any bad versions were found + try: + incorrect_files = check_versions() + for file, version in incorrect_files.items(): + print("ERROR: {} has incorrect version {}, expected version {}".format(file, version, CORRECT_VERSION)) + if incorrect_files: + exit(1) + except IOError as e: + print(e) # Likely no files found + exit(2)