Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent throwing RuntimeException when invalid proto is received #166

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ public class JsonFileErrorsWrite extends FeatureStoreWrite {

@Override
public PDone expand(PCollection<FeatureRowExtended> input) {
return input.apply("Map to strings", MapElements.into(kvs(strings(), strings())).via(
(rowExtended) -> {
try {
return KV.of(
rowExtended.getRow().getEntityName(),
JsonFormat.printer().omittingInsignificantWhitespace()
.print(rowExtended)
);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
)).apply("Write Error Json Files", new TextFileDynamicIO.Write(options, ".json"));
return input
.apply(
"Map to strings",
MapElements.into(kvs(strings(), strings()))
.via(
(rowExtended) -> {
try {
return KV.of(
rowExtended.getRow().getEntityName(),
JsonFormat.printer()
.omittingInsignificantWhitespace()
.print(rowExtended));
} catch (InvalidProtocolBufferException e) {
return KV.of(
rowExtended.getRow().getEntityName(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we assuming that rowExtended.getRow().getEntityName() was not the cause of the exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at worst, that line will return empty string.

e.toString());
}
}))
.apply("Write Error Json Files", new TextFileDynamicIO.Write(options, ".json"));
}
}