hudi-agent commented on code in PR #18371:
URL: https://github.com/apache/hudi/pull/18371#discussion_r3297052384


##########
hudi-common/src/main/java/org/apache/hudi/exception/ExceptionUtil.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.exception;
+
+import org.apache.hudi.common.util.StringUtils;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Util class for exception analysis.
+ */
+public final class ExceptionUtil {
+  private ExceptionUtil() {
+  }
+
+  /**
+   * Returns true if error message is contained in any nested exception of 
provided {@link Throwable}.
+   */
+  public static boolean validateErrorMsg(@Nonnull Throwable t, String 
errorMsg) {
+    if (StringUtils.isNullOrEmpty(errorMsg)) {
+      return false;
+    }
+
+    Throwable cause = t;
+    while (cause != null) {
+      if (cause.getMessage().contains(errorMsg)) {
+        return true;
+      }

Review Comment:
   🤖 `cause.getMessage()` can return null (e.g. exceptions constructed without 
a message, or many JVM-internal exceptions), which will trip an NPE here and 
replace the original Spark failure with a confusing NullPointerException from 
the error-handling path. Could you guard with `cause.getMessage() != null` 
before calling `.contains(...)`?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-common/src/main/java/org/apache/hudi/exception/ExceptionUtil.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.exception;
+
+import org.apache.hudi.common.util.StringUtils;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Util class for exception analysis.
+ */
+public final class ExceptionUtil {
+  private ExceptionUtil() {
+  }
+
+  /**
+   * Returns true if error message is contained in any nested exception of 
provided {@link Throwable}.
+   */
+  public static boolean validateErrorMsg(@Nonnull Throwable t, String 
errorMsg) {

Review Comment:
   🤖 nit: `validateErrorMsg` reads like it's asserting the message is 
well-formed — could you rename it to something like `containsErrorMessage` or 
`hasCauseWithMessage` to make it clear this is a containment check that returns 
a boolean?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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