Skip to content

Commit

Permalink
fix: stop showing message start in error (#12013) (#12140)
Browse files Browse the repository at this point in the history
Stops outputting the rpc message content's first 1000 characters in the error message,
that could end up even visible in the UI.
Instead only a part of the message details are output as debug-level log.

Co-authored-by: Tatu Lund <[email protected]>
  • Loading branch information
vaadin-bot and TatuLund authored Oct 25, 2021
1 parent c283395 commit b03a614
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ public void handleRpc(UI ui, Reader reader, VaadinRequest request)
* implementing the resync that would thus hide most symptoms of
* the actual root cause bugs.
*/
String messageStart = changeMessage;
if (messageStart.length() > 1000) {
messageStart = messageStart.substring(0, 1000);
}
String messageDetails = getMessageDetails(rpcRequest);
getLogger().debug("Unexpected message id from the client."
+ " Expected sync id: " + expectedId + ", got "
+ requestId + ". Message start: " + messageDetails);
throw new UnsupportedOperationException(
"Unexpected message id from the client."
+ " Expected sync id: " + expectedId + ", got "
+ requestId + ". Message start: "
+ messageStart);
+ requestId
+ ". more details logged on DEBUG level.");
}
} else {
// Message id ok, process RPCs
Expand Down Expand Up @@ -342,6 +342,32 @@ public void handleRpc(UI ui, Reader reader, VaadinRequest request)
}
}

private String getMessageDetails(RpcRequest rpcRequest) {
StringBuilder messageDetails = new StringBuilder();
JsonArray rpcArray = rpcRequest.getRpcInvocationsData();
if (rpcArray == null) {
return "{ no data }";
}

for (int i = 0; i < rpcArray.length(); i++) {
JsonObject json = rpcArray.get(i);
String type = json.hasKey("type") ? json.getString("type") : "";
Double node = json.hasKey("node") ? json.getNumber("node") : null;
Double feature = json.hasKey("feature") ? json.getNumber("feature")
: null;
appendAll(messageDetails, "{ type: ", type, " node: ",
String.valueOf(node), " feature: ", String.valueOf(feature),
" } ");
}
return messageDetails.toString();
}

private static void appendAll(StringBuilder builder, String... strings) {
for (String string : strings) {
builder.append(string);
}
}

/**
* Gets {@link RpcInvocationHandler}s map where the key is the type of the
* handler gotten via {@link RpcInvocationHandler#getRpcType()}.
Expand Down

0 comments on commit b03a614

Please sign in to comment.