Fail gracefully on bad stack

This commit is contained in:
David Boreham 2023-11-14 18:59:54 -07:00
parent 63ce394892
commit 918ef25f1a
3 changed files with 9 additions and 2 deletions

View File

@ -13,4 +13,4 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
stack_file_name = "stack.yml"
stack_file_name = "stack.yml"

View File

@ -26,7 +26,7 @@ import importlib.resources
from pathlib import Path
import yaml
from stack_orchestrator.constants import stack_file_name
from stack_orchestrator.util import include_exclude_check
from stack_orchestrator.util import include_exclude_check, error_exit
class GitProgress(git.RemoteProgress):
@ -245,6 +245,8 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches, branches
# In order to be compatible with Python 3.8 we need to use this hack to get the path:
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
stack_file_path = Path(__file__).absolute().parent.parent.joinpath("data", "stacks", stack, stack_file_name)
if not stack_file_path.exists():
error_exit(f"stack {stack} does not exist")
with stack_file_path:
stack_config = yaml.safe_load(open(stack_file_path, "r"))
# TODO: syntax check the input here

View File

@ -167,3 +167,8 @@ def global_options(ctx):
# TODO: hack
def global_options2(ctx):
return ctx.parent.obj
def error_exit(s):
print(f"ERROR: {s}")
sys.exit(1)