ptupitsyn commented on code in PR #2845:
URL: https://github.com/apache/ignite-3/pull/2845#discussion_r1395878341
##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientUtils.java:
##########
@@ -17,22 +17,61 @@
package org.apache.ignite.internal.client;
-import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
+import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
+import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.ignite.client.ClientOperationType;
import org.apache.ignite.client.IgniteClientConfiguration;
import org.apache.ignite.internal.client.proto.ClientOp;
+import org.apache.ignite.internal.lang.IgniteExceptionMapperUtil;
import org.apache.ignite.internal.logger.IgniteLogger;
import org.apache.ignite.internal.logger.Loggers;
import org.apache.ignite.internal.util.ExceptionUtils;
+import org.apache.ignite.lang.IgniteCheckedException;
+import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.lang.LoggerFactory;
/**
* Client utilities.
*/
public class ClientUtils {
+ /**
+ * Wraps an exception in an IgniteException, extracting trace identifier
and error code when the specified exception or one of its
+ * causes is an IgniteException itself.
+ *
+ * @param e Internal exception.
+ * @return Public exception.
+ */
+ public static IgniteException ensurePublicException(Throwable e) {
+ Objects.requireNonNull(e);
+
+ e = ExceptionUtils.unwrapCause(e);
+
+ if (e instanceof IgniteException) {
+ IgniteException iex = (IgniteException) e;
+
+ IgniteException copy =
ExceptionUtils.copyExceptionWithCause(e.getClass(), iex.traceId(), iex.code(),
e.getMessage(), e);
+ if (copy != null) {
+ return copy;
+ }
+
+ return new IgniteException(INTERNAL_ERR, "IgniteException-derived
class does not have required constructor: "
+ + e.getClass().getName(), iex);
+ }
+
+ e = IgniteExceptionMapperUtil.mapToPublicException(e);
+
+ if (e instanceof IgniteCheckedException) {
+ IgniteCheckedException iex = (IgniteCheckedException) e;
+
+ return new IgniteException(iex.traceId(), iex.code(),
e.getMessage(), e);
Review Comment:
I think we should use the same logic as above, with `copyExceptionWithCause`
- in case we'll have exception classes derived from `IgniteCheckedException`
later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]