mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
[Java][API CHANGE] Move exception to api module. (#24540)
This PR moves all exception classes from runtime module to api module. It's aiming to eliminate the confusion about ray exceptions. It means that Ray users don't need to touch runtime module when API programming after this PR. Note that this should be merged onto 2.0.
This commit is contained in:
parent
cc621ff08a
commit
af418fb729
35 changed files with 154 additions and 134 deletions
|
@ -330,9 +330,9 @@ The exception stack will be:
|
|||
File "ray/worker.py", line 1425, in get
|
||||
raise value
|
||||
ray.exceptions.CrossLanguageError: An exception raised from JAVA:
|
||||
io.ray.runtime.exception.RayTaskException: (pid=92253, ip=10.15.239.68) Error executing task df5a1a828c9685d3ffffffff01000000
|
||||
io.ray.api.exception.RayTaskException: (pid=92253, ip=10.15.239.68) Error executing task df5a1a828c9685d3ffffffff01000000
|
||||
at io.ray.runtime.task.TaskExecutor.execute(TaskExecutor.java:167)
|
||||
Caused by: io.ray.runtime.exception.CrossLanguageException: An exception raised from PYTHON:
|
||||
Caused by: io.ray.api.exception.CrossLanguageException: An exception raised from PYTHON:
|
||||
ray.exceptions.RayTaskError: ray::raise_exception() (pid=92252, ip=10.15.239.68)
|
||||
File "python/ray/_raylet.pyx", line 482, in ray._raylet.execute_task
|
||||
File "ray_exception.py", line 7, in raise_exception
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package io.ray.api.exception;
|
||||
|
||||
public class CrossLanguageException extends RayException {
|
||||
|
||||
public CrossLanguageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
import io.ray.api.id.ActorId;
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.runtime.util.NetworkUtil;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
|
||||
/**
|
||||
* Indicates that the actor died unexpectedly before finishing a task.
|
||||
|
@ -26,20 +24,19 @@ public class RayActorException extends RayException {
|
|||
this.actorId = actorId;
|
||||
}
|
||||
|
||||
public RayActorException(ActorId actorId, Throwable cause) {
|
||||
public RayActorException(int pid, String ipAddress, ActorId actorId, Throwable cause) {
|
||||
super(
|
||||
String.format(
|
||||
"(pid=%d, ip=%s) The actor %s died because of it's creation task failed",
|
||||
SystemUtil.pid(), NetworkUtil.getIpAddress(null), actorId.toString()),
|
||||
pid, ipAddress, actorId.toString()),
|
||||
cause);
|
||||
this.actorId = actorId;
|
||||
}
|
||||
|
||||
public RayActorException(Throwable cause) {
|
||||
public RayActorException(int pid, String ipAddress, Throwable cause) {
|
||||
super(
|
||||
String.format(
|
||||
"(pid=%d, ip=%s) The actor died because of it's creation task failed",
|
||||
SystemUtil.pid(), NetworkUtil.getIpAddress(null)),
|
||||
"(pid=%d, ip=%s) The actor died because of it's creation task failed", pid, ipAddress),
|
||||
cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package io.ray.api.exception;
|
||||
|
||||
public class RayException extends RuntimeException {
|
||||
|
||||
public RayException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RayException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
/** The exception represents that there is an intentional system exit. */
|
||||
public class RayIntentionalSystemExitException extends RuntimeException {
|
|
@ -0,0 +1,12 @@
|
|||
package io.ray.api.exception;
|
||||
|
||||
public class RayTaskException extends RayException {
|
||||
|
||||
public RayTaskException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RayTaskException(int pid, String ipAddress, String message, Throwable cause) {
|
||||
super(String.format("(pid=%d, ip=%s) %s", pid, ipAddress, message), cause);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
/** Indicate that there are some thing have timed out, including `Ray.get()` or others. */
|
||||
public class RayTimeoutException extends RayException {
|
|
@ -1,4 +1,4 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
/** Indicates that the worker died unexpectedly while executing a task. */
|
||||
public class RayWorkerException extends RayException {
|
|
@ -1,4 +1,4 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.api.exception;
|
||||
|
||||
import io.ray.api.id.ObjectId;
|
||||
|
|
@ -5,6 +5,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
|||
import com.google.protobuf.util.JsonFormat;
|
||||
import com.google.protobuf.util.JsonFormat.Printer;
|
||||
import io.ray.api.BaseActorHandle;
|
||||
import io.ray.api.exception.RayIntentionalSystemExitException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.id.JobId;
|
||||
import io.ray.api.id.ObjectId;
|
||||
|
@ -13,7 +14,6 @@ import io.ray.api.options.ActorLifetime;
|
|||
import io.ray.api.runtimecontext.ResourceValue;
|
||||
import io.ray.runtime.config.RayConfig;
|
||||
import io.ray.runtime.context.NativeWorkerContext;
|
||||
import io.ray.runtime.exception.RayIntentionalSystemExitException;
|
||||
import io.ray.runtime.functionmanager.FunctionManager;
|
||||
import io.ray.runtime.gcs.GcsClient;
|
||||
import io.ray.runtime.gcs.GcsClientOptions;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package io.ray.runtime.exception;
|
||||
|
||||
import io.ray.runtime.generated.Common.Language;
|
||||
|
||||
public class CrossLanguageException extends RayException {
|
||||
|
||||
private Language language;
|
||||
|
||||
public CrossLanguageException(io.ray.runtime.generated.Common.RayException exception) {
|
||||
super(
|
||||
String.format(
|
||||
"An exception raised from %s:\n%s",
|
||||
exception.getLanguage().name(), exception.getFormattedExceptionString()));
|
||||
this.language = exception.getLanguage();
|
||||
}
|
||||
|
||||
public Language getLanguage() {
|
||||
return this.language;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package io.ray.runtime.exception;
|
||||
|
||||
import io.ray.runtime.util.NetworkUtil;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
|
||||
public class RayTaskException extends RayException {
|
||||
|
||||
public RayTaskException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RayTaskException(String message, Throwable cause) {
|
||||
super(
|
||||
String.format(
|
||||
"(pid=%d, ip=%s) %s", SystemUtil.pid(), NetworkUtil.getIpAddress(null), message),
|
||||
cause);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package io.ray.runtime.object;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.ray.api.exception.RayTimeoutException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.id.ObjectId;
|
||||
import io.ray.api.id.UniqueId;
|
||||
import io.ray.runtime.context.WorkerContext;
|
||||
import io.ray.runtime.exception.RayTimeoutException;
|
||||
import io.ray.runtime.generated.Common.Address;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -3,15 +3,16 @@ package io.ray.runtime.object;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import io.ray.api.exception.RayWorkerException;
|
||||
import io.ray.api.exception.UnreconstructableException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.id.ObjectId;
|
||||
import io.ray.runtime.actor.NativeActorHandle;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.runtime.exception.RayWorkerException;
|
||||
import io.ray.runtime.exception.UnreconstructableException;
|
||||
import io.ray.runtime.generated.Common.ErrorType;
|
||||
import io.ray.runtime.serializer.RayExceptionSerializer;
|
||||
import io.ray.runtime.serializer.Serializer;
|
||||
import io.ray.runtime.util.IdUtil;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -148,7 +149,8 @@ public class ObjectSerializer {
|
|||
return new NativeRayObject(bytes, OBJECT_METADATA_TYPE_RAW);
|
||||
} else if (object instanceof RayTaskException) {
|
||||
RayTaskException taskException = (RayTaskException) object;
|
||||
byte[] serializedBytes = Serializer.encode(taskException.toBytes()).getLeft();
|
||||
byte[] serializedBytes =
|
||||
Serializer.encode(RayExceptionSerializer.toBytes(taskException)).getLeft();
|
||||
// serializedBytes is MessagePack serialized bytes
|
||||
// taskException.toBytes() is protobuf serialized bytes
|
||||
// Only OBJECT_METADATA_TYPE_RAW is raw bytes,
|
||||
|
@ -207,7 +209,7 @@ public class ObjectSerializer {
|
|||
|
||||
private static RayException deserializeRayException(byte[] msgPackData, ObjectId objectId) {
|
||||
// Serialization logic of task execution exception: an instance of
|
||||
// `io.ray.runtime.exception.RayTaskException`
|
||||
// `io.ray.api.exception.RayTaskException`
|
||||
// -> a `RayException` protobuf message
|
||||
// -> protobuf-serialized bytes
|
||||
// -> MessagePack-serialized bytes.
|
||||
|
@ -220,7 +222,7 @@ public class ObjectSerializer {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
return RayException.fromBytes(pbData);
|
||||
return RayExceptionSerializer.fromBytes(pbData);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't deserialize RayActorCreationTaskException object: " + objectId.toString(), e);
|
||||
|
@ -230,7 +232,7 @@ public class ObjectSerializer {
|
|||
private static RayException deserializeActorException(
|
||||
byte[] msgPackData, ActorId actorId, ObjectId objectId) {
|
||||
// Serialization logic of task execution exception: an instance of
|
||||
// `io.ray.runtime.exception.RayTaskException`
|
||||
// `io.ray.api.exception.RayTaskException`
|
||||
// -> a `RayException` protobuf message
|
||||
// -> protobuf-serialized bytes
|
||||
// -> MessagePack-serialized bytes.
|
||||
|
@ -247,7 +249,7 @@ public class ObjectSerializer {
|
|||
io.ray.runtime.generated.Common.RayErrorInfo rayErrorInfo =
|
||||
io.ray.runtime.generated.Common.RayErrorInfo.parseFrom(pbData);
|
||||
if (rayErrorInfo.getActorDiedError().hasCreationTaskFailureContext()) {
|
||||
return RayException.fromRayExceptionPB(
|
||||
return RayExceptionSerializer.fromRayExceptionPB(
|
||||
rayErrorInfo.getActorDiedError().getCreationTaskFailureContext());
|
||||
} else {
|
||||
// TODO(lixin) Generate friendly error message from RayErrorInfo.ActorDiedError's field
|
||||
|
|
|
@ -3,11 +3,11 @@ package io.ray.runtime.object;
|
|||
import com.google.common.base.Preconditions;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.WaitResult;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.id.ObjectId;
|
||||
import io.ray.api.id.UniqueId;
|
||||
import io.ray.runtime.context.WorkerContext;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.runtime.generated.Common.Address;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
|
@ -1,44 +1,48 @@
|
|||
package io.ray.runtime.exception;
|
||||
package io.ray.runtime.serializer;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import io.ray.api.exception.CrossLanguageException;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.runtime.generated.Common.Language;
|
||||
import io.ray.runtime.serializer.Serializer;
|
||||
|
||||
public class RayException extends RuntimeException {
|
||||
public class RayExceptionSerializer {
|
||||
|
||||
public RayException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RayException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
public static byte[] toBytes(RayException exception) {
|
||||
String formattedException =
|
||||
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(this);
|
||||
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(exception);
|
||||
io.ray.runtime.generated.Common.RayException.Builder builder =
|
||||
io.ray.runtime.generated.Common.RayException.newBuilder();
|
||||
builder.setLanguage(Language.JAVA);
|
||||
builder.setFormattedExceptionString(formattedException);
|
||||
builder.setSerializedException(ByteString.copyFrom(Serializer.encode(this).getLeft()));
|
||||
builder.setSerializedException(ByteString.copyFrom(Serializer.encode(exception).getLeft()));
|
||||
return builder.build().toByteArray();
|
||||
}
|
||||
|
||||
public static RayException fromBytes(byte[] serialized) throws InvalidProtocolBufferException {
|
||||
io.ray.runtime.generated.Common.RayException exception =
|
||||
io.ray.runtime.generated.Common.RayException.parseFrom(serialized);
|
||||
if (exception.getLanguage() == Language.JAVA) {
|
||||
return Serializer.decode(
|
||||
exception.getSerializedException().toByteArray(), RayException.class);
|
||||
} else {
|
||||
return new CrossLanguageException(
|
||||
String.format(
|
||||
"An exception raised from %s:\n%s",
|
||||
exception.getLanguage().name(), exception.getFormattedExceptionString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static RayException fromRayExceptionPB(
|
||||
io.ray.runtime.generated.Common.RayException rayExceptionPB) {
|
||||
if (rayExceptionPB.getLanguage() == Language.JAVA) {
|
||||
return Serializer.decode(
|
||||
rayExceptionPB.getSerializedException().toByteArray(), RayException.class);
|
||||
} else {
|
||||
return new CrossLanguageException(rayExceptionPB);
|
||||
return new CrossLanguageException(
|
||||
String.format(
|
||||
"An exception raised from %s:\n%s",
|
||||
rayExceptionPB.getLanguage().name(), rayExceptionPB.getFormattedExceptionString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static RayException fromBytes(byte[] serialized) throws InvalidProtocolBufferException {
|
||||
io.ray.runtime.generated.Common.RayException exception =
|
||||
io.ray.runtime.generated.Common.RayException.parseFrom(serialized);
|
||||
return fromRayExceptionPB(exception);
|
||||
}
|
||||
}
|
|
@ -1,19 +1,21 @@
|
|||
package io.ray.runtime.task;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.api.exception.RayIntentionalSystemExitException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import io.ray.api.id.JobId;
|
||||
import io.ray.api.id.TaskId;
|
||||
import io.ray.api.id.UniqueId;
|
||||
import io.ray.runtime.RayRuntimeInternal;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.runtime.exception.RayIntentionalSystemExitException;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.runtime.functionmanager.JavaFunctionDescriptor;
|
||||
import io.ray.runtime.functionmanager.RayFunction;
|
||||
import io.ray.runtime.generated.Common.TaskType;
|
||||
import io.ray.runtime.object.NativeRayObject;
|
||||
import io.ray.runtime.object.ObjectSerializer;
|
||||
import io.ray.runtime.util.NetworkUtil;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
@ -185,7 +187,11 @@ public abstract class TaskExecutor<T extends TaskExecutor.ActorContext> {
|
|||
try {
|
||||
serializedException =
|
||||
ObjectSerializer.serialize(
|
||||
new RayTaskException("Error executing task " + taskId, e));
|
||||
new RayTaskException(
|
||||
SystemUtil.pid(),
|
||||
NetworkUtil.getIpAddress(null),
|
||||
"Error executing task " + taskId,
|
||||
e));
|
||||
} catch (Exception unserializable) {
|
||||
// We should try-catch `ObjectSerializer.serialize` here. Because otherwise if the
|
||||
// application-level exception is not serializable. `ObjectSerializer.serialize`
|
||||
|
@ -205,13 +211,15 @@ public abstract class TaskExecutor<T extends TaskExecutor.ActorContext> {
|
|||
returnObjects.add(
|
||||
ObjectSerializer.serialize(
|
||||
new RayTaskException(
|
||||
SystemUtil.pid(),
|
||||
NetworkUtil.getIpAddress(null),
|
||||
String.format(
|
||||
"Function %s of task %s doesn't exist",
|
||||
String.join(".", rayFunctionInfo), taskId),
|
||||
e)));
|
||||
}
|
||||
} else {
|
||||
throw new RayActorException(e);
|
||||
throw new RayActorException(SystemUtil.pid(), NetworkUtil.getIpAddress(null), e);
|
||||
}
|
||||
}
|
||||
return returnObjects;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.ray.serve;
|
||||
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.api.exception.RayException;
|
||||
|
||||
public class RayServeException extends RayException {
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import io.ray.api.BaseActorHandle;
|
|||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.PyActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import io.ray.api.function.PyActorMethod;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.serve.Constants;
|
||||
import io.ray.serve.RayServeConfig;
|
||||
import io.ray.serve.RayServeException;
|
||||
|
|
|
@ -2,8 +2,8 @@ package io.ray.test;
|
|||
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
|
@ -5,9 +5,9 @@ import io.ray.api.ActorHandle;
|
|||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.PyActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.UnreconstructableException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.id.UniqueId;
|
||||
import io.ray.runtime.exception.UnreconstructableException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
|
@ -2,8 +2,8 @@ package io.ray.test;
|
|||
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.PendingCallsLimitExceededException;
|
||||
import io.ray.api.id.ObjectId;
|
||||
import io.ray.runtime.exception.PendingCallsLimitExceededException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
|
|
|
@ -5,13 +5,13 @@ import io.ray.api.ActorHandle;
|
|||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.PyActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.CrossLanguageException;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.api.function.PyActorClass;
|
||||
import io.ray.api.function.PyActorMethod;
|
||||
import io.ray.api.function.PyFunction;
|
||||
import io.ray.runtime.actor.NativeActorHandle;
|
||||
import io.ray.runtime.exception.CrossLanguageException;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import io.ray.runtime.generated.Common.Language;
|
||||
import io.ray.runtime.serializer.RayExceptionSerializer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -204,7 +204,7 @@ public class CrossLanguageInvocationTest extends BaseTest {
|
|||
String formattedException =
|
||||
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);
|
||||
io.ray.runtime.generated.Common.RayException exception =
|
||||
io.ray.runtime.generated.Common.RayException.parseFrom(e.toBytes());
|
||||
io.ray.runtime.generated.Common.RayException.parseFrom(RayExceptionSerializer.toBytes(e));
|
||||
Assert.assertEquals(exception.getFormattedExceptionString(), formattedException);
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,6 @@ public class CrossLanguageInvocationTest extends BaseTest {
|
|||
// ex is a Python exception(py_func_python_raise_exception) with no cause.
|
||||
Assert.assertTrue(ex instanceof CrossLanguageException);
|
||||
CrossLanguageException e = (CrossLanguageException) ex;
|
||||
Assert.assertEquals(e.getLanguage(), Language.PYTHON);
|
||||
// ex.cause is null.
|
||||
Assert.assertNull(ex.getCause());
|
||||
Assert.assertTrue(
|
||||
|
@ -278,7 +277,7 @@ public class CrossLanguageInvocationTest extends BaseTest {
|
|||
Assert.assertTrue(message.contains("py_func_nest_java_throw_exception"), message);
|
||||
Assert.assertEquals(
|
||||
org.apache.commons.lang3.StringUtils.countMatches(
|
||||
message, "io.ray.runtime.exception.RayTaskException"),
|
||||
message, "io.ray.api.exception.RayTaskException"),
|
||||
2);
|
||||
Assert.assertTrue(message.contains("py_func_java_throw_exception"), message);
|
||||
Assert.assertTrue(message.contains("java.lang.ArithmeticException: / by zero"), message);
|
||||
|
|
|
@ -2,8 +2,8 @@ package io.ray.test;
|
|||
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.options.ActorLifetime;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
|
@ -6,8 +6,8 @@ import com.google.common.collect.ImmutableList;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.options.ActorCreationOptions;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.task.TaskExecutor;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -3,12 +3,12 @@ package io.ray.test;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import io.ray.api.exception.RayWorkerException;
|
||||
import io.ray.api.exception.UnreconstructableException;
|
||||
import io.ray.api.function.RayFunc0;
|
||||
import io.ray.api.id.ObjectId;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.runtime.exception.RayWorkerException;
|
||||
import io.ray.runtime.exception.UnreconstructableException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -190,14 +190,16 @@ public class FailureTest extends BaseTest {
|
|||
Assert.expectThrows(
|
||||
RayTaskException.class,
|
||||
() -> {
|
||||
Ray.put(new RayTaskException("xxx", new RayActorException())).get();
|
||||
Ray.put(new RayTaskException(10008, "localhost", "xxx", new RayActorException()))
|
||||
.get();
|
||||
});
|
||||
Assert.assertEquals(ex1.getCause().getClass(), RayActorException.class);
|
||||
RayTaskException ex2 =
|
||||
Assert.expectThrows(
|
||||
RayTaskException.class,
|
||||
() -> {
|
||||
Ray.put(new RayTaskException("xxx", new RayWorkerException())).get();
|
||||
Ray.put(new RayTaskException(10008, "localhost", "xxx", new RayWorkerException()))
|
||||
.get();
|
||||
});
|
||||
Assert.assertEquals(ex2.getCause().getClass(), RayWorkerException.class);
|
||||
|
||||
|
@ -206,7 +208,10 @@ public class FailureTest extends BaseTest {
|
|||
Assert.expectThrows(
|
||||
RayTaskException.class,
|
||||
() -> {
|
||||
Ray.put(new RayTaskException("xxx", new UnreconstructableException(objectId))).get();
|
||||
Ray.put(
|
||||
new RayTaskException(
|
||||
10008, "localhost", "xxx", new UnreconstructableException(objectId)))
|
||||
.get();
|
||||
});
|
||||
Assert.assertEquals(ex3.getCause().getClass(), UnreconstructableException.class);
|
||||
Assert.assertEquals(((UnreconstructableException) ex3.getCause()).objectId, objectId);
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.ray.test;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.runtime.exception.RayTimeoutException;
|
||||
import io.ray.api.exception.RayTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.testng.Assert;
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableList;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import java.util.function.BiConsumer;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableList;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.runtime.exception.UnreconstructableException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import io.ray.api.exception.UnreconstructableException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.testng.Assert;
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.google.common.base.Preconditions;
|
|||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.exception.RayActorException;
|
||||
import io.ray.api.parallelactor.*;
|
||||
import io.ray.runtime.exception.RayActorException;
|
||||
import io.ray.runtime.util.SystemUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -6,11 +6,11 @@ import io.ray.api.ObjectRef;
|
|||
import io.ray.api.PlacementGroups;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.api.WaitResult;
|
||||
import io.ray.api.exception.RayException;
|
||||
import io.ray.api.id.ActorId;
|
||||
import io.ray.api.placementgroup.PlacementGroup;
|
||||
import io.ray.api.placementgroup.PlacementGroupState;
|
||||
import io.ray.api.placementgroup.PlacementStrategy;
|
||||
import io.ray.runtime.exception.RayException;
|
||||
import java.util.List;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -2,7 +2,7 @@ package io.ray.test;
|
|||
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.runtime.exception.RayTaskException;
|
||||
import io.ray.api.exception.RayTaskException;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -68,7 +68,8 @@ jclass java_ray_timeout_exception_class;
|
|||
jclass java_ray_pending_calls_limit_exceeded_exception_class;
|
||||
|
||||
jclass java_ray_actor_exception_class;
|
||||
jmethodID java_ray_exception_to_bytes;
|
||||
jclass java_ray_exception_serializer_class;
|
||||
jmethodID java_ray_exception_serializer_to_bytes;
|
||||
|
||||
jclass java_jni_exception_util_class;
|
||||
jmethodID java_jni_exception_util_get_stack_trace;
|
||||
|
@ -244,21 +245,25 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|||
java_system_class = LoadClass(env, "java/lang/System");
|
||||
java_system_gc = env->GetStaticMethodID(java_system_class, "gc", "()V");
|
||||
|
||||
java_ray_exception_class = LoadClass(env, "io/ray/runtime/exception/RayException");
|
||||
java_ray_exception_class = LoadClass(env, "io/ray/api/exception/RayException");
|
||||
java_ray_intentional_system_exit_exception_class =
|
||||
LoadClass(env, "io/ray/runtime/exception/RayIntentionalSystemExitException");
|
||||
LoadClass(env, "io/ray/api/exception/RayIntentionalSystemExitException");
|
||||
|
||||
java_ray_timeout_exception_class =
|
||||
LoadClass(env, "io/ray/runtime/exception/RayTimeoutException");
|
||||
LoadClass(env, "io/ray/api/exception/RayTimeoutException");
|
||||
|
||||
java_ray_actor_exception_class =
|
||||
LoadClass(env, "io/ray/runtime/exception/RayActorException");
|
||||
LoadClass(env, "io/ray/api/exception/RayActorException");
|
||||
|
||||
java_ray_pending_calls_limit_exceeded_exception_class =
|
||||
LoadClass(env, "io/ray/runtime/exception/PendingCallsLimitExceededException");
|
||||
LoadClass(env, "io/ray/api/exception/PendingCallsLimitExceededException");
|
||||
|
||||
java_ray_exception_to_bytes =
|
||||
env->GetMethodID(java_ray_exception_class, "toBytes", "()[B");
|
||||
java_ray_exception_serializer_class =
|
||||
LoadClass(env, "io/ray/runtime/serializer/RayExceptionSerializer");
|
||||
java_ray_exception_serializer_to_bytes =
|
||||
env->GetStaticMethodID(java_ray_exception_serializer_class,
|
||||
"toBytes",
|
||||
"(Lio/ray/api/exception/RayException;)[B");
|
||||
|
||||
java_jni_exception_util_class = LoadClass(env, "io/ray/runtime/util/JniExceptionUtil");
|
||||
java_jni_exception_util_get_stack_trace = env->GetStaticMethodID(
|
||||
|
@ -437,6 +442,7 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) {
|
|||
env->DeleteGlobalRef(java_ray_intentional_system_exit_exception_class);
|
||||
env->DeleteGlobalRef(java_ray_timeout_exception_class);
|
||||
env->DeleteGlobalRef(java_ray_actor_exception_class);
|
||||
env->DeleteGlobalRef(java_ray_exception_serializer_class);
|
||||
env->DeleteGlobalRef(java_jni_exception_util_class);
|
||||
env->DeleteGlobalRef(java_base_id_class);
|
||||
env->DeleteGlobalRef(java_abstract_message_lite_class);
|
||||
|
|
|
@ -115,14 +115,17 @@ extern jclass java_ray_pending_calls_limit_exceeded_exception_class;
|
|||
/// RayIntentionalSystemExitException class
|
||||
extern jclass java_ray_intentional_system_exit_exception_class;
|
||||
|
||||
/// RayActorCreationTaskException class
|
||||
/// RayActorException class
|
||||
extern jclass java_ray_actor_exception_class;
|
||||
|
||||
/// RayExceptionSerializer class
|
||||
extern jclass java_ray_exception_serializer_class;
|
||||
|
||||
/// RayTimeoutException class
|
||||
extern jclass java_ray_timeout_exception_class;
|
||||
|
||||
/// toBytes method of RayException
|
||||
extern jmethodID java_ray_exception_to_bytes;
|
||||
/// RayExceptionSerializer to bytes
|
||||
extern jmethodID java_ray_exception_serializer_to_bytes;
|
||||
|
||||
/// JniExceptionUtil class
|
||||
extern jclass java_jni_exception_util_class;
|
||||
|
@ -673,7 +676,9 @@ inline NativeT JavaProtobufObjectToNativeProtobufObject(JNIEnv *env, jobject jav
|
|||
inline std::shared_ptr<LocalMemoryBuffer> SerializeActorCreationException(
|
||||
JNIEnv *env, jthrowable creation_exception) {
|
||||
jbyteArray exception_jbyte_array = static_cast<jbyteArray>(
|
||||
env->CallObjectMethod(creation_exception, java_ray_exception_to_bytes));
|
||||
env->CallStaticObjectMethod(java_ray_exception_serializer_class,
|
||||
java_ray_exception_serializer_to_bytes,
|
||||
creation_exception));
|
||||
int len = env->GetArrayLength(exception_jbyte_array);
|
||||
auto buf = std::make_shared<LocalMemoryBuffer>(len);
|
||||
env->GetByteArrayRegion(
|
||||
|
|
Loading…
Add table
Reference in a new issue