ptupitsyn commented on code in PR #2845:
URL: https://github.com/apache/ignite-3/pull/2845#discussion_r1395651991


##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientUtils.java:
##########
@@ -17,22 +17,58 @@
 
 package org.apache.ignite.internal.client;
 
-import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
-
+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;
+
+            try {
+                return ExceptionUtils.copyExceptionWithCause(e.getClass(), 
iex.traceId(), iex.code(), e.getMessage(), e);

Review Comment:
   `copyExceptionWithCause` can return null - what happens in this case?



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientUtils.java:
##########
@@ -17,22 +17,58 @@
 
 package org.apache.ignite.internal.client;
 
-import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
-
+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;
+
+            try {
+                return ExceptionUtils.copyExceptionWithCause(e.getClass(), 
iex.traceId(), iex.code(), e.getMessage(), e);
+            } catch (Exception ex) {
+                throw new RuntimeException("IgniteException-derived class does 
not have required constructor: "

Review Comment:
   `copyExceptionWithCause` returns null when there is no constructor, or am I 
mistaken?



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientUtils.java:
##########
@@ -17,22 +17,58 @@
 
 package org.apache.ignite.internal.client;
 
-import static org.apache.ignite.internal.util.ExceptionUtils.sneakyThrow;
-
+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;
+
+            try {
+                return ExceptionUtils.copyExceptionWithCause(e.getClass(), 
iex.traceId(), iex.code(), e.getMessage(), e);
+            } catch (Exception ex) {
+                throw new RuntimeException("IgniteException-derived class does 
not have required constructor: "
+                        + e.getClass().getName(), ex);
+            }
+        }
+
+        e = IgniteExceptionMapperUtil.mapToPublicException(e);
+
+        if (e instanceof IgniteCheckedException) {
+            IgniteCheckedException iex = (IgniteCheckedException) e;
+
+            return new IgniteException(iex.traceId(), iex.code(), 
e.getMessage(), e);
+        }
+
+        return (IgniteException) e;

Review Comment:
   `mapToPublicException` potentially returns `e` as is. We should always throw 
a new exception to ensure correct stack trace. 
   
   By the way, do we have a test for this part of the method?



-- 
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]

Reply via email to