api/schema: don't crash on eval error
This commit is contained in:
parent
c194adc181
commit
97ea9312ac
@ -10,6 +10,7 @@ from clan_cli.dirs import (
|
||||
nixpkgs_source,
|
||||
specific_flake_dir,
|
||||
)
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
from ..types import FlakeName
|
||||
@ -75,5 +76,5 @@ def machine_schema(
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
print(proc.stderr, file=sys.stderr)
|
||||
raise Exception(f"Failed to read schema:\n{proc.stderr}")
|
||||
raise ClanError(f"Failed to read schema:\n{proc.stderr}")
|
||||
return json.loads(proc.stdout)
|
||||
|
@ -22,6 +22,21 @@ def test_machines(api: TestClient, test_flake: FlakeForTest) -> None:
|
||||
assert response.json() == {"machines": [{"name": "test", "status": "unknown"}]}
|
||||
|
||||
|
||||
@pytest.mark.with_core
|
||||
def test_schema_errors(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
|
||||
# make sure that eval errors do not raise an internal server error
|
||||
response = api.put(
|
||||
f"/api/{test_flake_with_core.name}/schema",
|
||||
json={"imports": ["some-inavlid-import"]},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
# expect error to contain "error: string 'some-inavlid-import' doesn't represent an absolute path"
|
||||
assert (
|
||||
"error: string 'some-inavlid-import' doesn't represent an absolute path"
|
||||
in response.json()["detail"][0]["msg"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.with_core
|
||||
def test_configure_machine(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
|
||||
# ensure error 404 if machine does not exist when accessing the config
|
||||
|
Loading…
Reference in New Issue
Block a user