denis-chudov commented on code in PR #7606:
URL: https://github.com/apache/ignite-3/pull/7606#discussion_r2853724128
##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -471,6 +471,29 @@ public static Throwable unwrapCause(Throwable e) {
return e;
}
+ /**
+ * Unwraps exception cause until the given cause type from the given
wrapper exception. If there is no any cause of the expected type
+ * then the original exception will be thrown.
+ *
+ * @param e The exception to unwrap.
+ * @param causeType Expected type of a cause to look up.
+ * @return The desired cause of the exception.
+ * @throws Throwable Original exception in case if there is no cause with
given type.
+ */
+ public static <T extends Throwable> T unwrapCause(Throwable e, Class<T>
causeType) {
+ Throwable cause = e;
+
+ while (!causeType.isAssignableFrom(cause.getClass()) &&
cause.getCause() != null) {
Review Comment:
I would set maximum steps count here
##########
modules/core/src/main/java/org/apache/ignite/internal/util/ExceptionUtils.java:
##########
@@ -471,6 +471,29 @@ public static Throwable unwrapCause(Throwable e) {
return e;
}
+ /**
+ * Unwraps exception cause until the given cause type from the given
wrapper exception. If there is no any cause of the expected type
+ * then the original exception will be thrown.
+ *
+ * @param e The exception to unwrap.
+ * @param causeType Expected type of a cause to look up.
+ * @return The desired cause of the exception.
+ * @throws Throwable Original exception in case if there is no cause with
given type.
+ */
+ public static <T extends Throwable> T unwrapCause(Throwable e, Class<T>
causeType) {
+ Throwable cause = e;
+
+ while (!causeType.isAssignableFrom(cause.getClass()) &&
cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+
+ if (!causeType.isInstance(cause)) {
+ sneakyThrow(e);
+ }
Review Comment:
Looks weird. Why would unwrapCause throw the exception that it tries to
process?
It may return either null or original exception, but not throw
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteServerImpl.java:
##########
@@ -617,12 +633,60 @@ private static void sync(CompletableFuture<Void> future) {
try {
future.get();
} catch (ExecutionException e) {
+ if (hasCause(e, NodeStartException.class)) {
+ sneakyThrow(e.getCause());
+ }
+
throw sneakyThrow(tryToCopyExceptionWithCause(e));
} catch (InterruptedException e) {
throw sneakyThrow(e);
}
}
+ private static void throwIfError(Throwable exception) {
+ Error error;
+
+ try {
+ error = unwrapCause(exception, Error.class);
+ } catch (Throwable originalException) {
+ return;
+ }
+
+ throwIfExceptionInInitializerError(error);
+
+ throw new NodeStartException("Error occurred during node start, check
.jar libraries and JVM execution arguments.", error);
+ }
+
+ private static void throwIfExceptionInInitializerError(Error error) {
+ ExceptionInInitializerError initializerError;
+ try {
+ initializerError = unwrapCause(error,
ExceptionInInitializerError.class);
+ } catch (Error otherError) {
+ return;
+ }
+
+ Throwable initializerErrorCause = initializerError.getCause();
+
+ if (initializerErrorCause == null) {
+ throw new NodeStartException(
+ "Error during static components initialization with
unknown cause, check .jar libraries and JVM execution arguments.",
+ initializerError
+ );
+ }
+
+ if (initializerErrorCause instanceof IllegalAccessException) {
+ throw new NodeStartException(
+ "Error during static components initialization due to
illegal code access, check --add-opens JVM execution arguments.",
+ initializerErrorCause
+ );
+ }
+
+ throw new NodeStartException(
+ "Error during static components initialization, check .jar
libraries and JVM execution arguments.",
Review Comment:
```suggestion
"Error during static components initialization, make sure
that classpath and JVM execution arguments are correct.",
```
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteServerImpl.java:
##########
@@ -617,12 +633,60 @@ private static void sync(CompletableFuture<Void> future) {
try {
future.get();
} catch (ExecutionException e) {
+ if (hasCause(e, NodeStartException.class)) {
+ sneakyThrow(e.getCause());
+ }
+
throw sneakyThrow(tryToCopyExceptionWithCause(e));
} catch (InterruptedException e) {
throw sneakyThrow(e);
}
}
+ private static void throwIfError(Throwable exception) {
+ Error error;
+
+ try {
+ error = unwrapCause(exception, Error.class);
+ } catch (Throwable originalException) {
+ return;
+ }
+
+ throwIfExceptionInInitializerError(error);
+
+ throw new NodeStartException("Error occurred during node start, check
.jar libraries and JVM execution arguments.", error);
+ }
+
+ private static void throwIfExceptionInInitializerError(Error error) {
+ ExceptionInInitializerError initializerError;
+ try {
+ initializerError = unwrapCause(error,
ExceptionInInitializerError.class);
+ } catch (Error otherError) {
+ return;
+ }
+
+ Throwable initializerErrorCause = initializerError.getCause();
+
+ if (initializerErrorCause == null) {
+ throw new NodeStartException(
+ "Error during static components initialization with
unknown cause, check .jar libraries and JVM execution arguments.",
Review Comment:
```suggestion
"Error during static components initialization, make
sure that classpath and JVM execution arguments are correct.",
```
I would remove "with unknown"
--
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]