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

refactor(framework) Add try-except block to flwr stop for JSON output #4712

Merged
merged 10 commits into from
Dec 16, 2024
Merged
52 changes: 30 additions & 22 deletions src/py/flwr/cli/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,42 @@ def stop(
] = None,
) -> None:
"""Stop a run."""
# Load and validate federation config
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)
try:
# Load and validate federation config
typer.secho("Loading project configuration... ", fg=typer.colors.BLUE)

pyproject_path = app / FAB_CONFIG_FILE if app else None
config, errors, warnings = load_and_validate(path=pyproject_path)
config = process_loaded_project_config(config, errors, warnings)
federation, federation_config = validate_federation_in_project_config(
federation, config
)
exit_if_no_address(federation_config, "stop")
pyproject_path = app / FAB_CONFIG_FILE if app else None
config, errors, warnings = load_and_validate(path=pyproject_path)
config = process_loaded_project_config(config, errors, warnings)
federation, federation_config = validate_federation_in_project_config(
federation, config
)
exit_if_no_address(federation_config, "stop")

try:
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
channel = init_channel(app, federation_config, auth_plugin)
stub = ExecStub(channel) # pylint: disable=unused-variable # noqa: F841
try:
auth_plugin = try_obtain_cli_auth_plugin(app, federation)
channel = init_channel(app, federation_config, auth_plugin)
stub = ExecStub(channel) # pylint: disable=unused-variable # noqa: F841

typer.secho(f"✋ Stopping run ID {run_id}...", fg=typer.colors.GREEN)
_stop_run(stub, run_id=run_id)
typer.secho(f"✋ Stopping run ID {run_id}...", fg=typer.colors.GREEN)
_stop_run(stub, run_id=run_id)

except ValueError as err:
typer.secho(
f"❌ {err}",
fg=typer.colors.RED,
bold=True,
)
except ValueError as err:
typer.secho(
f"❌ {err}",
fg=typer.colors.RED,
bold=True,
)
raise typer.Exit(code=1) from err
finally:
channel.close()
except (
typer.Exit,
Exception,
) as err: # pylint: disable=broad-except, W0612 # noqa: F841
raise typer.Exit(code=1) from err
finally:
channel.close()
pass
danieljanes marked this conversation as resolved.
Show resolved Hide resolved


def _stop_run(
Expand Down