diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 9ae4e86..4c212c7 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -1,6 +1,8 @@ import re from typing import List, Optional +from pydantic import ValidationError + import compose_viz.spec.compose_spec as spec from compose_viz.models.compose import Compose, Service from compose_viz.models.extends import Extends @@ -13,7 +15,13 @@ class Parser: pass def parse(self, file_path: str) -> Compose: - compose_data: spec.ComposeSpecification = spec.ComposeSpecification.parse_file(file_path) + compose_data: spec.ComposeSpecification + + try: + compose_data = spec.ComposeSpecification.parse_file(file_path) + except ValidationError as e: + raise RuntimeError(f"Error parsing file '{file_path}': {e}") + services: List[Service] = [] assert compose_data.services is not None, "No services found, aborting." diff --git a/tests/test_parser.py b/tests/test_parser.py index cf996c1..c7fa2ef 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -3,12 +3,12 @@ import pytest from compose_viz.parser import Parser -def test_parser_error_parsing_file() -> None: +def test_parser_invalid_yaml() -> None: with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/ymls/others/invalid.yml'.*"): Parser().parse("tests/ymls/others/invalid.yml") -def test_parser_invalid_yaml() -> None: +def test_parser_empty_yaml() -> None: with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/ymls/others/empty.yml'.*"): Parser().parse("tests/ymls/others/empty.yml")