snuyanzin commented on code in PR #29906:
URL: https://github.com/apache/flink/pull/29906#discussion_r4626189544


##########
flink-core-api/src/main/java/org/apache/flink/api/common/errors/FlinkThrowable.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.flink.api.common.errors;
+
+import org.apache.flink.annotation.PublicEvolving;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * An exception that can carry a {@link FlinkError}. Implemented by {@code 
FlinkRuntimeException},
+ * {@code FlinkException} and their subclasses.
+ *
+ * <p>An exception created from an error and its arguments has the error's 
formatted template as its
+ * detail message. An exception created with a free-text message has no error.
+ */
+@PublicEvolving
+public interface FlinkThrowable {
+
+    /** The error, or empty if the exception was created with a free-text 
message. */
+    Optional<FlinkError> getError();
+
+    /** The arguments by parameter name, in declaration order. Empty without 
an error. */
+    Map<String, Object> getErrorArgs();
+
+    /**
+     * Returns the argument of the given parameter.
+     *
+     * @throws IllegalArgumentException if the exception has no argument for 
the parameter
+     */
+    @SuppressWarnings("unchecked")
+    default <T> T getErrorArg(String name) {
+        final Map<String, Object> arguments = getErrorArgs();
+        if (!arguments.containsKey(name)) {
+            throw new IllegalArgumentException(
+                    String.format("The exception has no argument for parameter 
'%s'.", name));
+        }
+        return (T) arguments.get(name);
+    }

Review Comment:
   ```suggestion
   default <T> T getErrorArg(String name) {
           final Object argument = getErrorArgs().get(name);
           if (argument == null) {
               throw new IllegalArgumentException(
                       String.format("The exception has no argument for 
parameter '%s'.", name));
           }
           return (T) argument;
       }
   ```
   isn't `validateArguments` rejecting `null` arg already?



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