Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error if -config file has wrong suffix #4201

Merged

Conversation

valosekj
Copy link
Member

@valosekj valosekj commented Aug 18, 2023

Checklist

GitHub

PR contents

Description

When working with the sct_run_batch script, I incorrectly defined the suffix of the config file to .sh. The error raised by the sct_run_batch script was not very specific. Thus, I added an error raise if the config file is not YML or JSON.

master branch:

$ sct_run_batch -config config.sh

--
Spinal Cord Toolbox (git-master-d6aeaef52466129b5f24a56fa250403839bd0166)

sct_run_batch -config config.sh
--

configuring
Traceback (most recent call last):
  File "/Users/valosek/code/sct_latest/spinalcordtoolbox/scripts/sct_run_batch.py", line 597, in <module>
    main(sys.argv[1:])
  File "/Users/valosek/code/sct_latest/spinalcordtoolbox/scripts/sct_run_batch.py", line 359, in main
    config_keys = set(config.keys())
UnboundLocalError: local variable 'config' referenced before assignment

jv/raise_error_if_sct_run_batch_config_has_wrong_suffix branch:

$ sct_run_batch -config config.sh

--
Spinal Cord Toolbox (git-master-d6aeaef52466129b5f24a56fa250403839bd0166*)

sct_run_batch -config config.sh
--

configuring
Traceback (most recent call last):
  File "/Users/valosek/code/sct_latest/spinalcordtoolbox/scripts/sct_run_batch.py", line 599, in <module>
    main(sys.argv[1:])
  File "/Users/valosek/code/sct_latest/spinalcordtoolbox/scripts/sct_run_batch.py", line 353, in main
    raise ValueError('Unrecognized configuration file type: {}'.format(ext))
ValueError: Unrecognized configuration file type: .sh

Copy link
Member

@mguaypaq mguaypaq left a comment

Choose a reason for hiding this comment

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

Thanks for converting this to an if...elif...else pattern! That's much better.

spinalcordtoolbox/scripts/sct_run_batch.py Show resolved Hide resolved
@mguaypaq mguaypaq merged commit 8b8f9bd into master Aug 21, 2023
24 checks passed
@mguaypaq mguaypaq deleted the jv/raise_error_if_sct_run_batch_config_has_wrong_suffix branch August 21, 2023 15:25
@joshuacwnewton joshuacwnewton added the enhancement category: improves performance/results of an existing feature label Oct 30, 2023
@joshuacwnewton joshuacwnewton changed the title Raise error if sct_run_batch config file has wrong suffix Raise error if -config file has wrong suffix Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement category: improves performance/results of an existing feature sct_run_batch context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants