chore: implement new error format

This commit is contained in:
Xyphuz 2022-05-27 19:56:30 +08:00
parent 2e50d1b4d1
commit 83e4f3422f
2 changed files with 11 additions and 3 deletions

View file

@ -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."

View file

@ -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")