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


##########
flink-core/src/main/java/org/apache/flink/util/FlinkException.java:
##########
@@ -52,5 +75,50 @@ public FlinkException(Throwable cause) {
      */
     public FlinkException(String message, Throwable cause) {
         super(message, cause);
+        this.error = null;
+        this.errorArgs = null;
+    }
+
+    /**
+     * Creates a new exception for the given error, with the formatted 
template of the error as the
+     * message and null as the cause.
+     *
+     * @param error The error
+     * @param arguments The arguments for the parameters of the error, in 
declaration order
+     * @throws IllegalArgumentException if the error isn't an enum constant or 
the arguments don't
+     *     match the parameters of the error
+     */
+    @PublicEvolving
+    public FlinkException(FlinkError error, Object... arguments) {
+        this(error, null, arguments);
+    }
+
+    /**
+     * Creates a new exception for the given error, with the formatted 
template of the error as the
+     * message and the given cause.
+     *
+     * @param error The error
+     * @param cause The exception that caused this exception
+     * @param arguments The arguments for the parameters of the error, in 
declaration order
+     * @throws IllegalArgumentException if the error isn't an enum constant or 
the arguments don't
+     *     match the parameters of the error
+     */
+    @PublicEvolving
+    public FlinkException(FlinkError error, @Nullable Throwable cause, 
Object... arguments) {
+        super(FlinkThrowableUtils.formatMessage(error, cause, arguments), 
cause);
+        this.error = Preconditions.checkNotNull(error);
+        this.errorArgs = FlinkThrowableUtils.toArgumentMap(error, arguments);
+    }
+
+    @PublicEvolving
+    @Override
+    public Optional<FlinkError> getError() {
+        return Optional.ofNullable(error);
+    }
+
+    @PublicEvolving
+    @Override
+    public Map<String, Object> getErrorArgs() {
+        return errorArgs == null ? Collections.emptyMap() : errorArgs;

Review Comment:
   ```suggestion
           return errorArgs == null ? Map.of() : errorArgs;
   ```



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