Repository: ray-project/ray
File: python/ray/scripts/scripts.py (Python)

Code before:
        )

    try:
        try:
            actor_handle = ray.get_actor(name, namespace=namespace)
        except Exception as e:
            raise click.ClickException(
                f"No named actor found: {name} (namespace={namespace}): {e}"
            )

        if force:
            try:
                ray.kill(actor_handle, no_restart=no_restart)
                click.echo(f"Actor killed (force): {name}")
                return
            except Exception as e:
                raise click.ClickException(f"Failed to force kill actor: {e}")

        else:
            try:
                actor_handle.__ray_terminate__.remote()
                click.echo(f"Requested graceful termination for actor: {name}")
            except Exception as e:
                raise click.ClickException(
                    f"Failed to request graceful termination: {e}"
                )
    except click.ClickException:
        raise
    except Exception as e:
        raise click.ClickException(f"Failed to kill actor: {e}")


@cli.command()
@click.argument("cluster_config_file", required=True, type=str)
@click.option(
    "--min-workers",
    required=False,
    type=int,
    help="Override the configured min worker node count for the cluster.",
)
@click.option(
    "--max-workers",
    required=False,
    type=int,
    help="Override the configured max worker node count for the cluster.",
)
@click.option(
    "--no-restart",
    is_flag=True,
    default=False,
    help=(

Review comment (bug):
there isn't any expected path where this would fail, so no need to catch and wrap the exception in a `ClickException`

Code after:

    # Connect to the cluster (no driver logging)
    if not ray.is_initialized():
        ray.init(address=address, namespace=namespace, log_to_driver=False)

    if not force and no_restart:
        click.echo(
            "WARNING: --no-restart flag is only effective with --force (graceful termination does not support controlling actor restart).",
            err=True,
        )

    try:
        actor_handle = ray.get_actor(name, namespace=namespace)
    except ValueError:
        raise click.ClickException(
            f"No named actor found: {name} (namespace={namespace})"
        )
    if force:
        ray.kill(actor_handle, no_restart=no_restart)
        click.echo(f"Actor killed (force): {name}")
    else:
        actor_handle.__ray_terminate__.remote()
        click.echo(f"Requested graceful termination for actor: {name}")


@cli.command()
@click.argument("cluster_config_file", required=True, type=str)
@click.option(
    "--min-workers",
    required=False,
    type=int,
    help="Override the configured min worker node count for the cluster.",
)
@click.option(
    "--max-workers",
    required=False,
    type=int,
    help="Override the configured max worker node count for the cluster.",
)
@click.option(
    "--no-restart",
    is_flag=True,
    default=False,
    help=(
        "Whether to skip restarting Ray services during the update. "
        "This avoids interrupting running jobs."
    ),
)
@click.option(
    "--restart-only",
    is_flag=True,