Remove instances of 'raise Exception' (#7523)

This commit is contained in:
Edward Oakes
2020-03-10 17:51:22 -07:00
committed by GitHub
parent fdb528514b
commit 7b609ca211
13 changed files with 134 additions and 131 deletions
+48 -48
View File
@@ -439,8 +439,8 @@ def get_gpu_ids():
A list of GPU IDs.
"""
if _mode() == LOCAL_MODE:
raise Exception("ray.get_gpu_ids() currently does not work in LOCAL "
"MODE.")
raise RuntimeError("ray.get_gpu_ids() currently does not work in "
"local_mode.")
all_resource_ids = global_worker.core_worker.resource_ids()
assigned_ids = [
@@ -466,9 +466,8 @@ def get_resource_ids():
resource reserved for this worker.
"""
if _mode() == LOCAL_MODE:
raise Exception(
"ray.get_resource_ids() currently does not work in LOCAL "
"MODE.")
raise RuntimeError("ray.get_resource_ids() currently does not work in "
"local_mode.")
return global_worker.core_worker.resource_ids()
@@ -482,7 +481,7 @@ def get_webui_url():
The URL of the web UI as a string.
"""
if _global_node is None:
raise Exception("Ray has not been initialized/connected.")
raise RuntimeError("Ray has not been initialized/connected.")
return _global_node.webui_url
@@ -687,10 +686,10 @@ def init(address=None,
"called.")
return
else:
raise Exception("Perhaps you called ray.init twice by accident? "
"This error can be suppressed by passing in "
"'ignore_reinit_error=True' or by calling "
"'ray.shutdown()' prior to 'ray.init()'.")
raise RuntimeError("Maybe you called ray.init twice by accident? "
"This error can be suppressed by passing in "
"'ignore_reinit_error=True' or by calling "
"'ray.shutdown()' prior to 'ray.init()'.")
# Convert hostnames to numerical IP address.
if node_ip_address is not None:
@@ -743,44 +742,45 @@ def init(address=None,
else:
# In this case, we are connecting to an existing cluster.
if num_cpus is not None or num_gpus is not None:
raise Exception("When connecting to an existing cluster, num_cpus "
"and num_gpus must not be provided.")
raise ValueError(
"When connecting to an existing cluster, num_cpus "
"and num_gpus must not be provided.")
if resources is not None:
raise Exception("When connecting to an existing cluster, "
"resources must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"resources must not be provided.")
if num_redis_shards is not None:
raise Exception("When connecting to an existing cluster, "
"num_redis_shards must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"num_redis_shards must not be provided.")
if redis_max_clients is not None:
raise Exception("When connecting to an existing cluster, "
"redis_max_clients must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"redis_max_clients must not be provided.")
if memory is not None:
raise Exception("When connecting to an existing cluster, "
"memory must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"memory must not be provided.")
if object_store_memory is not None:
raise Exception("When connecting to an existing cluster, "
"object_store_memory must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"object_store_memory must not be provided.")
if redis_max_memory is not None:
raise Exception("When connecting to an existing cluster, "
"redis_max_memory must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"redis_max_memory must not be provided.")
if plasma_directory is not None:
raise Exception("When connecting to an existing cluster, "
"plasma_directory must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"plasma_directory must not be provided.")
if huge_pages:
raise Exception("When connecting to an existing cluster, "
"huge_pages must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"huge_pages must not be provided.")
if temp_dir is not None:
raise Exception("When connecting to an existing cluster, "
"temp_dir must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"temp_dir must not be provided.")
if plasma_store_socket_name is not None:
raise Exception("When connecting to an existing cluster, "
"plasma_store_socket_name must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"plasma_store_socket_name must not be provided.")
if raylet_socket_name is not None:
raise Exception("When connecting to an existing cluster, "
"raylet_socket_name must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"raylet_socket_name must not be provided.")
if _internal_config is not None:
raise Exception("When connecting to an existing cluster, "
"_internal_config must not be provided.")
raise ValueError("When connecting to an existing cluster, "
"_internal_config must not be provided.")
# In this case, we only need to connect the node.
ray_params = ray.parameter.RayParams(
@@ -1604,13 +1604,13 @@ def wait(object_ids, num_returns=1, timeout=None):
return [], []
if len(object_ids) != len(set(object_ids)):
raise Exception("Wait requires a list of unique object IDs.")
raise ValueError("Wait requires a list of unique object IDs.")
if num_returns <= 0:
raise Exception(
raise ValueError(
"Invalid number of objects to return %d." % num_returns)
if num_returns > len(object_ids):
raise Exception("num_returns cannot be greater than the number "
"of objects provided to ray.wait.")
raise ValueError("num_returns cannot be greater than the number "
"of objects provided to ray.wait.")
timeout = timeout if timeout is not None else 10**6
timeout_milliseconds = int(timeout * 1000)
@@ -1676,8 +1676,8 @@ def make_decorator(num_return_vals=None,
or is_cython(function_or_class)):
# Set the remote function default resources.
if max_reconstructions is not None:
raise Exception("The keyword 'max_reconstructions' is not "
"allowed for remote functions.")
raise ValueError("The keyword 'max_reconstructions' is not "
"allowed for remote functions.")
return ray.remote_function.RemoteFunction(
Language.PYTHON, function_or_class, None, num_cpus, num_gpus,
@@ -1686,17 +1686,17 @@ def make_decorator(num_return_vals=None,
if inspect.isclass(function_or_class):
if num_return_vals is not None:
raise Exception("The keyword 'num_return_vals' is not allowed "
"for actors.")
raise TypeError("The keyword 'num_return_vals' is not "
"allowed for actors.")
if max_calls is not None:
raise Exception("The keyword 'max_calls' is not allowed for "
"actors.")
raise TypeError("The keyword 'max_calls' is not "
"allowed for actors.")
return worker.make_actor(function_or_class, num_cpus, num_gpus,
memory, object_store_memory, resources,
max_reconstructions)
raise Exception("The @ray.remote decorator must be applied to "
raise TypeError("The @ray.remote decorator must be applied to "
"either a function or to a class.")
return decorator
@@ -1815,7 +1815,7 @@ def remote(*args, **kwargs):
num_gpus = kwargs["num_gpus"] if "num_gpus" in kwargs else None
resources = kwargs.get("resources")
if not isinstance(resources, dict) and resources is not None:
raise Exception("The 'resources' keyword argument must be a "
raise TypeError("The 'resources' keyword argument must be a "
"dictionary, but received type {}.".format(
type(resources)))
if resources is not None: