sk0x50 commented on code in PR #2845:
URL: https://github.com/apache/ignite-3/pull/2845#discussion_r1399392103
##########
modules/client/src/main/java/org/apache/ignite/internal/client/ClientUtils.java:
##########
@@ -17,22 +17,92 @@
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.UUID;
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 Throwable ensurePublicException(Throwable e) {
+ Objects.requireNonNull(e);
+
+ e = ExceptionUtils.unwrapCause(e);
+
+ if (e instanceof IgniteException) {
+ return copyExceptionWithCauseIfPossible((IgniteException) e);
+ }
+
+ if (e instanceof IgniteCheckedException) {
+ return copyExceptionWithCauseIfPossible((IgniteCheckedException)
e);
+ }
+
+ e = IgniteExceptionMapperUtil.mapToPublicException(e);
+
+ return new IgniteException(INTERNAL_ERR, e.getMessage(), e);
+ }
+
+ /**
+ * Try to copy exception using ExceptionUtils.copyExceptionWithCause and
return new exception if it was not possible.
+ *
+ * @param e Exception.
+ * @return Properly copied exception or a new error, if exception can not
be copied.
+ */
+ private static Throwable copyExceptionWithCauseIfPossible(IgniteException
e) {
Review Comment:
It can be optimized a bit using the `TraceableException` interface.
--
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]