chore: implement new error format
This commit is contained in:
parent
2e50d1b4d1
commit
83e4f3422f
2 changed files with 11 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
import re
|
import re
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
import compose_viz.spec.compose_spec as spec
|
import compose_viz.spec.compose_spec as spec
|
||||||
from compose_viz.models.compose import Compose, Service
|
from compose_viz.models.compose import Compose, Service
|
||||||
from compose_viz.models.extends import Extends
|
from compose_viz.models.extends import Extends
|
||||||
|
@ -13,7 +15,13 @@ class Parser:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def parse(self, file_path: str) -> Compose:
|
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] = []
|
services: List[Service] = []
|
||||||
|
|
||||||
assert compose_data.services is not None, "No services found, aborting."
|
assert compose_data.services is not None, "No services found, aborting."
|
||||||
|
|
|
@ -3,12 +3,12 @@ import pytest
|
||||||
from compose_viz.parser import Parser
|
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'.*"):
|
with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/ymls/others/invalid.yml'.*"):
|
||||||
Parser().parse("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'.*"):
|
with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/ymls/others/empty.yml'.*"):
|
||||||
Parser().parse("tests/ymls/others/empty.yml")
|
Parser().parse("tests/ymls/others/empty.yml")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue