From 02425eb4bcbaa15bdc290bf5458d25969a05c3b3 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:31:17 +0200 Subject: [PATCH 1/8] exit 10 for archspec failure --- src/mpsd_software_manager/mpsd_software.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index eed840a..1be51b9 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -830,7 +830,7 @@ def get_native_microarchitecture(): msg += "Documentation of package: https://archspec.readthedocs.io/" logging.error(msg) - sys.exit(1) + sys.exit(10) else: # we have found archspec and executed it if process.returncode == 0: # sanity check microarch = process.stdout.strip() -- GitLab From e92cc489d8d6899b83f065f7492c508acfe68b3f Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:33:33 +0200 Subject: [PATCH 2/8] exit20 for usage of unavailable package_set --- src/mpsd_software_manager/mpsd_software.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 1be51b9..ac29f17 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -919,7 +919,7 @@ def install_environment( msg += f" in release {mpsd_release}. " msg += "Use 'available' command to see list of available package_sets." logging.error(msg) - sys.exit(1) + sys.exit(20) # Install the package_sets with os_chdir(package_set_dir): -- GitLab From 706a9d79cafa1bda05730c701324a75e276cf90e Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:34:13 +0200 Subject: [PATCH 3/8] update tests for wrong package_set --- tests/test_mpsd_software.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 79fc35c..7aae7fe 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -192,7 +192,7 @@ def test_record_script_execution_summary(tmp_path): def test_install_environment_wrong_package_set(tmp_path): """Test exception is raised for non-existing package_set.""" - # exits with exit code 1 when wrong package_sets are provided + # exits with exit code 20 when wrong package_sets are provided with pytest.raises(SystemExit) as e: mod.install_environment( mpsd_release="dev-23a", @@ -200,7 +200,7 @@ def test_install_environment_wrong_package_set(tmp_path): root_dir=(tmp_path), ) assert e.type == SystemExit - assert e.value.code == 1 + assert e.value.code == 20 def test_install_environment_wrong_mpsd_release(tmp_path): -- GitLab From ef485ca45aac1bd0b62d7d1337cd7d8f53ab5774 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:37:14 +0200 Subject: [PATCH 4/8] exit30 for already initialised directory --- src/mpsd_software_manager/mpsd_software.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index ac29f17..751108f 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -1104,7 +1104,7 @@ def initialize_environment(root_dir: Path) -> None: logging.getLogger("print").info( f"Error: Directory {str(root_dir)} is already initialized." ) - sys.exit(1) + sys.exit(30) else: # create the init file init_file.touch() -- GitLab From 06b048dbda72624f4e13b1a03fc887d480a3e352 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:38:24 +0200 Subject: [PATCH 5/8] test exit30 for preinitialised directory --- tests/test_mpsd_software.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 7aae7fe..c7bc12c 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -532,11 +532,11 @@ def test_initialize_environment(tmp_path): with open(log_file, "r") as f: assert (f"Initialising MPSD software instance at {tmp_path}") in f.read() - # test that calling again results in warning and exit code 1 + # test that calling again results in warning and exit code 30 with pytest.raises(SystemExit) as pytest_wrapped_e: mod.initialize_environment(tmp_path) assert pytest_wrapped_e.type == SystemExit - assert pytest_wrapped_e.value.code == 1 + assert pytest_wrapped_e.value.code == 30 def test_get_root_dir(tmp_path): -- GitLab From 3531d3a7d24e87dc46458298a3eee4c7216b3d1b Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:40:33 +0200 Subject: [PATCH 6/8] exit40 to indicate absence of initialisation --- src/mpsd_software_manager/mpsd_software.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 751108f..442cc8d 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -1162,7 +1162,7 @@ def get_root_dir() -> Path: + f"and the hidden file `{config_vars['init_file']}`." " to check if a directory is initialised" ) - sys.exit(1) + sys.exit(40) def main(): -- GitLab From 8ec88e837f1d7d503ae5466ec08e401991d7360e Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:41:39 +0200 Subject: [PATCH 7/8] test exit40 as the code for uninitialised folder --- tests/test_mpsd_software.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index c7bc12c..1d2a26e 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -542,11 +542,11 @@ def test_initialize_environment(tmp_path): def test_get_root_dir(tmp_path): """Test that the root directory is correct.""" with mod.os_chdir(tmp_path): - # test that function exists with error 1 if root dir doesn't exist + # test that function exists with error 40 if root dir doesn't exist with pytest.raises(SystemExit) as pytest_wrapped_e: mod.get_root_dir() assert pytest_wrapped_e.type == SystemExit - assert pytest_wrapped_e.value.code == 1 + assert pytest_wrapped_e.value.code == 40 # test that initialize_environment creates the root dir mod.initialize_environment(tmp_path) -- GitLab From a10480232695916df89f7d8970ea053f7036e48b Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 28 Jun 2023 14:49:03 +0200 Subject: [PATCH 8/8] add a table of exit codes --- development.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/development.rst b/development.rst index 4d029e4..f034c98 100644 --- a/development.rst +++ b/development.rst @@ -17,3 +17,20 @@ Then every time you commit, pre-commit will run all checks defined in `.pre-comm you can run the pre-commit checks manually by running:: pre-commit run --all-files + +Debugging exit codes +-------------------- +Non zero exit codes are used to indicate that the program exited due to an error. +There are multiple ways to debug this. You could run the program with more verbose logging:: + + mpsd-software -l debug ... + +Here is a list of exit codes and what they mean: ++-----------+------------------------------------------+----------------------------------------------------------------------------------+ +| Exit code | Reason | Solution | ++===========+==========================================+==================================================================================+ +| 10 | Call of 'archspec cpu' failed | Please install archspec, for example via 'pipx install archspec' | +| 20 | Requested package set is not available | Use 'available' command to see list of available package_sets | +| 30 | Current directory is already initialised | Check if you are in the right directory | +| 40 | Current directory is not initialised | Check if you are in the right directory, if so use 'init' command to initialise | ++-----------+------------------------------------------+----------------------------------------------------------------------------------+ -- GitLab