You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "krisztina-zsihovszki (via GitHub)" <gi...@apache.org> on 2023/03/03 08:52:23 UTC

[GitHub] [nifi] krisztina-zsihovszki opened a new pull request, #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

krisztina-zsihovszki opened a new pull request, #7007:
URL: https://github.com/apache/nifi/pull/7007

   <!-- 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. -->
   
   # Summary
   
   [NIFI-4651](https://issues.apache.org/jira/browse/NIFI-4651)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [x] JDK 11
     - [x] JDK 17
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] krisztina-zsihovszki commented on a diff in pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "krisztina-zsihovszki (via GitHub)" <gi...@apache.org>.
krisztina-zsihovszki commented on code in PR #7007:
URL: https://github.com/apache/nifi/pull/7007#discussion_r1132444658


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -836,7 +870,17 @@ boolean isFragmentedTransactionReady(final List<FlowFile> flowFiles, final Long
         return false;  // not enough FlowFiles for this transaction. Return them all to queue.
     }
 
+    private FlowFile addErrorAttributesToFlowFile(final ProcessSession session, FlowFile flowFile, final Exception exception) {
+        final Map<String, String> attributes = new HashMap<>();
+        attributes.put(ERROR_MESSAGE_ATTR, exception.getMessage());
 
+        if (exception instanceof SQLException) {
+            attributes.put(ERROR_CODE_ATTR, valueOf(((SQLException) exception).getErrorCode()));
+            attributes.put(ERROR_SQL_STATE_ATTR, valueOf(((SQLException) exception).getSQLState()));
+        }
+
+        return session.putAllAttributes(flowFile, attributes);

Review Comment:
   The method adds extra attributes to the FlowFile, it does not remove any existing attribute. (Added a check in unit tests to verify this.) 



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] Lehel44 commented on pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "Lehel44 (via GitHub)" <gi...@apache.org>.
Lehel44 commented on PR #7007:
URL: https://github.com/apache/nifi/pull/7007#issuecomment-1462515384

   Thanks for the contribution @krisztina-zsihovszki. Reviewing.


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] mattyb149 commented on pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 commented on PR #7007:
URL: https://github.com/apache/nifi/pull/7007#issuecomment-1478034229

   +1 LGTM, Merging to main and support/nifi-1.x


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] Lehel44 commented on a diff in pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "Lehel44 (via GitHub)" <gi...@apache.org>.
Lehel44 commented on code in PR #7007:
URL: https://github.com/apache/nifi/pull/7007#discussion_r1131793273


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);
                     break;
                 case Retry:
                     getLogger().error("Failed to update database for {} due to {}; it is possible that retrying the operation will succeed, so routing to retry",
-                            new Object[] {i, e}, e);
+                            new Object[] {flowFile, exception}, exception);
                     break;
                 case Self:
-                    getLogger().error("Failed to update database for {} due to {};", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {};",  new Object[] {flowFile, exception}, exception);
                     break;
             }
         });
         return RollbackOnFailure.createOnError(onFlowFileError);
     }
 
+    private ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
+        ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError
+                = ExceptionHandler.createOnGroupError(context, session, result, REL_FAILURE, REL_RETRY);
+        onGroupError = onGroupError.andThen((ctx, flowFileGroup, errorTypesResult, exception) -> {
+
+            switch (errorTypesResult.destination()) {
+                case Failure:
+                    List<FlowFile> flowFilesToFailure = getFlowFilesOnRelationShip(result, REL_FAILURE);
+                    Optional.ofNullable(flowFilesToFailure).map(flowFiles ->
+                        result.getRoutedFlowFiles().put(REL_FAILURE, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                   break;
+                case Retry:
+                    List<FlowFile> flowFilesToRetry = getFlowFilesOnRelationShip(result, REL_RETRY);
+                    Optional.ofNullable(flowFilesToRetry).map(flowFiles ->
+                            result.getRoutedFlowFiles().put(REL_RETRY, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                    break;
+            }
+        });
+        return onGroupError;
+    }

Review Comment:
   The RoutingResult::getRoutedFlowFiles already returns an empty map, so the getFlowFilesOnRelationShip does not need to use Optional and should return an empty list in case the flowfiles for the specified relationship are missing. This means that `flowFilesToFailure` variable in onGroupError cannot be null and also doesn't need to be wrapped in Optionals. I'd also recommend simplifying the 2-branched switch to an if statement for visibility and extracting the condition on getting the Relationship based on the ErrorTypesResult.Destination since both branches depend on that value i.e. -> the if statement is not needed.
   
   ```suggestion
       private ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
           ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError =
                   ExceptionHandler.createOnGroupError(context, session, result, REL_FAILURE, REL_RETRY);
   
           onGroupError = onGroupError.andThen((ctx, flowFileGroup, errorTypesResult, exception) -> {
               Relationship relationship = errorTypesResult.destination() == ErrorTypes.Destination.Failure ? REL_FAILURE : REL_RETRY;
               List<FlowFile> flowFilesToRelationship = getFlowFilesOnRelationship(result, relationship);
               result.getRoutedFlowFiles().put(relationship, addErrorAttributesToFlowFilesInGroup(session, flowFilesToRelationship, flowFileGroup.getFlowFiles(), exception));
           });
   
           return onGroupError;
       }
   ```



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] mattyb149 closed pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "mattyb149 (via GitHub)" <gi...@apache.org>.
mattyb149 closed pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes
URL: https://github.com/apache/nifi/pull/7007


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] krisztina-zsihovszki commented on pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "krisztina-zsihovszki (via GitHub)" <gi...@apache.org>.
krisztina-zsihovszki commented on PR #7007:
URL: https://github.com/apache/nifi/pull/7007#issuecomment-1453519466

   recheck


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] Lehel44 commented on a diff in pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

Posted by "Lehel44 (via GitHub)" <gi...@apache.org>.
Lehel44 commented on code in PR #7007:
URL: https://github.com/apache/nifi/pull/7007#discussion_r1131757370


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);

Review Comment:
   The logger can handle arbitrary number of arguments.
   
   ```suggestion
                       getLogger().error("Failed to update database for {}; routing to failure", flowFile, exception);
   ```



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);
                     break;
                 case Retry:
                     getLogger().error("Failed to update database for {} due to {}; it is possible that retrying the operation will succeed, so routing to retry",
-                            new Object[] {i, e}, e);
+                            new Object[] {flowFile, exception}, exception);

Review Comment:
   Same here.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);
                     break;
                 case Retry:
                     getLogger().error("Failed to update database for {} due to {}; it is possible that retrying the operation will succeed, so routing to retry",
-                            new Object[] {i, e}, e);
+                            new Object[] {flowFile, exception}, exception);
                     break;
                 case Self:
-                    getLogger().error("Failed to update database for {} due to {};", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {};",  new Object[] {flowFile, exception}, exception);
                     break;
             }
         });
         return RollbackOnFailure.createOnError(onFlowFileError);
     }
 
+    private ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
+        ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError
+                = ExceptionHandler.createOnGroupError(context, session, result, REL_FAILURE, REL_RETRY);
+        onGroupError = onGroupError.andThen((ctx, flowFileGroup, errorTypesResult, exception) -> {
+
+            switch (errorTypesResult.destination()) {
+                case Failure:
+                    List<FlowFile> flowFilesToFailure = getFlowFilesOnRelationShip(result, REL_FAILURE);
+                    Optional.ofNullable(flowFilesToFailure).map(flowFiles ->
+                        result.getRoutedFlowFiles().put(REL_FAILURE, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                   break;
+                case Retry:
+                    List<FlowFile> flowFilesToRetry = getFlowFilesOnRelationShip(result, REL_RETRY);
+                    Optional.ofNullable(flowFilesToRetry).map(flowFiles ->
+                            result.getRoutedFlowFiles().put(REL_RETRY, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                    break;
+            }
+        });
+        return onGroupError;
+    }

Review Comment:
   The RoutingResult::getRoutedFlowFiles already returns an empty map, so the getFlowFilesOnRelationShip does not need to use Optional and should return an empty list in case the flowfiles for the specified relationship are missing. This means that `flowFilesToFailure` variable in onGroupError cannot be null and also doesn't need to be wrapped in Optionals. I'd also recommend simplifying the 2-branched switch to an if statement for visibility and extracting the condition on getting the Relationship based on the ErrorTypesResult.Destination since both branches depend on that value i.e. the if statement is not needed.
   
   ```suggestion
       private ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
           ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError =
                   ExceptionHandler.createOnGroupError(context, session, result, REL_FAILURE, REL_RETRY);
   
           onGroupError = onGroupError.andThen((ctx, flowFileGroup, errorTypesResult, exception) -> {
               Relationship relationship = errorTypesResult.destination() == ErrorTypes.Destination.Failure ? REL_FAILURE : REL_RETRY;
               List<FlowFile> flowFilesToRelationship = getFlowFilesOnRelationship(result, relationship);
               result.getRoutedFlowFiles().put(relationship, addErrorAttributesToFlowFilesInGroup(session, flowFilesToRelationship, flowFileGroup.getFlowFiles(), exception));
           });
   
           return onGroupError;
       }
   ```



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -836,7 +870,17 @@ boolean isFragmentedTransactionReady(final List<FlowFile> flowFiles, final Long
         return false;  // not enough FlowFiles for this transaction. Return them all to queue.
     }
 
+    private FlowFile addErrorAttributesToFlowFile(final ProcessSession session, FlowFile flowFile, final Exception exception) {
+        final Map<String, String> attributes = new HashMap<>();
+        attributes.put(ERROR_MESSAGE_ATTR, exception.getMessage());
 
+        if (exception instanceof SQLException) {
+            attributes.put(ERROR_CODE_ATTR, valueOf(((SQLException) exception).getErrorCode()));
+            attributes.put(ERROR_SQL_STATE_ATTR, valueOf(((SQLException) exception).getSQLState()));
+        }
+
+        return session.putAllAttributes(flowFile, attributes);

Review Comment:
   Is it guaranteed that the flowfile doesn't have original attributes before being updated with the error ones or does the method only update and not replace the flowfile attributes?



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);
                     break;
                 case Retry:
                     getLogger().error("Failed to update database for {} due to {}; it is possible that retrying the operation will succeed, so routing to retry",
-                            new Object[] {i, e}, e);
+                            new Object[] {flowFile, exception}, exception);
                     break;
                 case Self:
-                    getLogger().error("Failed to update database for {} due to {};", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {};",  new Object[] {flowFile, exception}, exception);

Review Comment:
   Same here.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -458,23 +461,58 @@ void apply(final ProcessContext context, final ProcessSession session, final Fun
 
     private ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
         ExceptionHandler.OnError<FunctionContext, FlowFile> onFlowFileError = createOnError(context, session, result, REL_FAILURE, REL_RETRY);
-        onFlowFileError = onFlowFileError.andThen((c, i, r, e) -> {
-            switch (r.destination()) {
+        onFlowFileError = onFlowFileError.andThen((ctx, flowFile, errorTypesResult, exception) -> {
+            flowFile = addErrorAttributesToFlowFile(session, flowFile, exception);
+
+            switch (errorTypesResult.destination()) {
                 case Failure:
-                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {}; routing to failure", new Object[] {flowFile, exception}, exception);
                     break;
                 case Retry:
                     getLogger().error("Failed to update database for {} due to {}; it is possible that retrying the operation will succeed, so routing to retry",
-                            new Object[] {i, e}, e);
+                            new Object[] {flowFile, exception}, exception);
                     break;
                 case Self:
-                    getLogger().error("Failed to update database for {} due to {};", new Object[] {i, e}, e);
+                    getLogger().error("Failed to update database for {} due to {};",  new Object[] {flowFile, exception}, exception);
                     break;
             }
         });
         return RollbackOnFailure.createOnError(onFlowFileError);
     }
 
+    private ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError(final ProcessContext context, final ProcessSession session, final RoutingResult result) {
+        ExceptionHandler.OnError<RollbackOnFailure, FlowFileGroup> onGroupError
+                = ExceptionHandler.createOnGroupError(context, session, result, REL_FAILURE, REL_RETRY);
+        onGroupError = onGroupError.andThen((ctx, flowFileGroup, errorTypesResult, exception) -> {
+
+            switch (errorTypesResult.destination()) {
+                case Failure:
+                    List<FlowFile> flowFilesToFailure = getFlowFilesOnRelationShip(result, REL_FAILURE);
+                    Optional.ofNullable(flowFilesToFailure).map(flowFiles ->
+                        result.getRoutedFlowFiles().put(REL_FAILURE, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                   break;
+                case Retry:
+                    List<FlowFile> flowFilesToRetry = getFlowFilesOnRelationShip(result, REL_RETRY);
+                    Optional.ofNullable(flowFilesToRetry).map(flowFiles ->
+                            result.getRoutedFlowFiles().put(REL_RETRY, addErrorAttributesToFlowFilesInGroup(session, flowFiles, flowFileGroup.getFlowFiles(), exception)));
+                    break;
+            }
+        });
+        return onGroupError;
+    }
+
+    private List<FlowFile> addErrorAttributesToFlowFilesInGroup(ProcessSession session, List<FlowFile> flowFilesOnRelationship, List<FlowFile> flowFilesInGroup, Exception exception) {
+        return flowFilesOnRelationship.stream()
+                    .map(ff ->  flowFilesInGroup.contains(ff) ? addErrorAttributesToFlowFile(session, ff, exception) : ff)
+                    .collect(toList());
+    }
+
+    private List<FlowFile> getFlowFilesOnRelationShip(RoutingResult result, final Relationship relationship) {
+        return Optional.of(result.getRoutedFlowFiles())
+                .orElse(emptyMap())
+                .get(relationship);
+    }

Review Comment:
   Since the getRoutedFlowFiles already returns an empty map, the optional is not necessary here.
   
   ```suggestion
       private List<FlowFile> getFlowFilesOnRelationship(RoutingResult result, final Relationship relationship) {
           return Optional.ofNullable(result.getRoutedFlowFiles().get(relationship))
                   .orElse(emptyList());
       }
   ```



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org