Repository: ray-project/ray
File: python/ray/autoscaler/v2/instance_manager/cloud_providers/kuberay/cloud_provider.py (Python)

Code before:
        scale_request = self._initialize_scale_request(
            to_launch={}, to_delete_instances=ids
        )
        if scale_request.worker_groups_with_pending_deletes:
            errors_msg = (
                "There are workers to be deleted from: "
                f"{scale_request.worker_groups_with_pending_deletes}. "
                "Waiting for them to be deleted before adding new workers "
                " to be deleted"
            )
            logger.warning(errors_msg)
            self._add_terminate_errors(
                ids,
                request_id,
                details=errors_msg,
            )
            return

        try:
            self._submit_scale_request(scale_request)
        except Exception as e:
            logger.exception(f"Error terminating nodes: {scale_request}")
            self._add_terminate_errors(ids, request_id, details=str(e), e=e)

    def launch(self, shape: Dict[NodeType, int], request_id: str) -> None:
        if request_id in self._requests:
            # This request is already processed.
            return
        self._requests.add(request_id)

        scale_request = self._initialize_scale_request(
            to_launch=shape, to_delete_instances=[]
        )

        if scale_request.worker_groups_with_pending_deletes:
            error_msg = (
                "There are workers to be deleted from: "
                f"{scale_request.worker_groups_with_pending_deletes}. "
                "Waiting for them to be deleted before creating new workers."
            )
            logger.warning(error_msg)
            self._add_launch_errors(
                shape,
                request_id,
                details=error_msg,
            )
            return

        try:
            self._submit_scale_request(scale_request)
        except Exception as e:

Review comment (suggestion):
```suggestion
            logger.exception(f"Error terminating nodes: {scale_request}")
```

Code after:
        try:
            scale_request = self._initialize_scale_request(
                to_launch={}, to_delete_instances=ids
            )

            if scale_request.worker_groups_with_pending_deletes:
                errors_msg = (
                    "There are workers to be deleted from: "
                    f"{scale_request.worker_groups_with_pending_deletes}. "
                    "Waiting for them to be deleted before adding new workers "
                    " to be deleted"
                )
                logger.warning(errors_msg)
                self._add_terminate_errors(
                    ids,
                    request_id,
                    details=errors_msg,
                )
                return

            self._submit_scale_request(scale_request)
            # Only add to processed requests if successful
            self._requests.add(request_id)

        except Exception as e:
            logger.exception(f"Error terminating nodes: {scale_request or 'N/A'}")
            self._add_terminate_errors(ids, request_id, details=str(e), e=e)

    def launch(self, shape: Dict[NodeType, int], request_id: str) -> None:
        if request_id in self._requests:
            # This request is already processed.
            return

        scale_request = None
        try:
            scale_request = self._initialize_scale_request(
                to_launch=shape, to_delete_instances=[]
            )

            if scale_request.worker_groups_with_pending_deletes:
                error_msg = (
                    "There are workers to be deleted from: "
                    f"{scale_request.worker_groups_with_pending_deletes}. "
                    "Waiting for them to be deleted before creating new workers."
                )
                logger.warning(error_msg)
                self._add_launch_errors(
                    shape,
                    request_id,
                    details=error_msg,
                )