ahmedabu98 commented on code in PR #30372:
URL: https://github.com/apache/beam/pull/30372#discussion_r1504849972


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PreparePubsubWriteDoFn.java:
##########
@@ -125,18 +140,42 @@ public void process(
       @Timestamp Instant ts,
       BoundedWindow window,
       PaneInfo paneInfo,
-      OutputReceiver<PubsubMessage> o) {
+      MultiOutputReceiver o)
+      throws Exception {
     ValueInSingleWindow<InputT> valueInSingleWindow =
         ValueInSingleWindow.of(element, ts, window, paneInfo);
-    PubsubMessage message = formatFunction.apply(valueInSingleWindow);
+    PubsubMessage message;
+    try {
+      message = formatFunction.apply(valueInSingleWindow);
+    } catch (Exception e) {
+      badRecordRouter.route(
+          o,
+          element,
+          inputCoder,
+          e,
+          "Failed to serialize PubSub message with provided format function");
+      return;
+    }
     if (topicFunction != null) {
-      message = 
message.withTopic(topicFunction.apply(valueInSingleWindow).asPath());
+      try {
+        message = 
message.withTopic(topicFunction.apply(valueInSingleWindow).asPath());
+      } catch (Exception e) {
+        badRecordRouter.route(
+            o, element, inputCoder, e, "Failed to determine PubSub topic using 
topic function");
+        return;
+      }
     }
     try {
       validatePubsubMessageSize(message, maxPublishBatchSize);
     } catch (SizeLimitExceededException e) {
-      throw new IllegalArgumentException(e);
+      badRecordRouter.route(
+          o,
+          element,
+          inputCoder,
+          new IllegalArgumentException(e),
+          "PubSub message size limit exceeded");

Review Comment:
   nit: to avoid confusion, can we make this message more generic? Looking at 
the validation code, it can fail for reasons other than message size (e.g. 
attribute key/value size too large)



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