Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch config upload validation errors #2211

Merged
merged 13 commits into from
Oct 8, 2024
Merged
6 changes: 5 additions & 1 deletion data_safe_haven/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ def upload(
else:
logger.critical(f"Configuration file '{file}' not found.")
raise typer.Exit(1)
config = SREConfig.from_yaml(config_yaml)
try:
config = SREConfig.from_yaml(config_yaml)
except DataSafeHavenTypeError as exc:
logger.error("Check for missing or incorrect fields in the configuration.")
raise typer.Exit(1) from exc

# Present diff to user
if (not force) and SREConfig.remote_exists(context, filename=config.filename):
Expand Down
2 changes: 1 addition & 1 deletion data_safe_haven/serialisers/yaml_serialisable_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def from_yaml(cls: type[T], settings_yaml: str) -> T:
)
for error in exc.errors():
logger.error(
f"[red]{'.'.join(map(str, error.get('loc', [])))}: {error.get('input', '')}[/] - {error.get('msg', '')}"
f"{error.get('msg', '')}: [red]{'.'.join(map(str, error.get('loc', [])))}.[/] Original input: [red]{error.get('input', '')}[/]"
)
msg = f"{cls.config_type} configuration is invalid."
raise DataSafeHavenTypeError(msg) from exc
Expand Down
Loading