diff --git a/src/py/flwr/cli/run/run.py b/src/py/flwr/cli/run/run.py index 2715ea3599e0..cabd5707d5c0 100644 --- a/src/py/flwr/cli/run/run.py +++ b/src/py/flwr/cli/run/run.py @@ -87,19 +87,23 @@ def run( ] = False, ) -> None: """Run Flower App.""" - typer.secho("Loading project configuration... ", fg=typer.colors.BLUE) + try: + typer.secho("Loading project configuration... ", fg=typer.colors.BLUE) - pyproject_path = app / "pyproject.toml" if app else None - config, errors, warnings = load_and_validate(path=pyproject_path) - config = validate_project_config(config, errors, warnings) - federation, federation_config = validate_federation_in_project_config( - federation, config - ) + pyproject_path = app / "pyproject.toml" if app else None + config, errors, warnings = load_and_validate(path=pyproject_path) + config = validate_project_config(config, errors, warnings) + federation, federation_config = validate_federation_in_project_config( + federation, config + ) - if "address" in federation_config: - _run_with_exec_api(app, federation_config, config_overrides, stream) - else: - _run_without_exec_api(app, federation_config, config_overrides, federation) + if "address" in federation_config: + _run_with_exec_api(app, federation_config, config_overrides, stream) + else: + _run_without_exec_api(app, federation_config, config_overrides, federation) + # pylint: disable=broad-except, unused-variable + except (typer.Exit, SystemExit, Exception): + _print_json_error() # pylint: disable-next=too-many-locals @@ -198,3 +202,7 @@ def _run_without_exec_api( check=True, text=True, ) + + +def _print_json_error() -> None: + """Print error message as JSON."""