OpenVidu / openvidu

OpenVidu Platform main repository
https://openvidu.io
Apache License 2.0
1.9k stars 464 forks source link

Exception messages don't reach either logs or client RPC #735

Closed j1elo closed 2 years ago

j1elo commented 2 years ago

Describe the bug

When openvidu-server catches an error and throws an Exception, the exception's message is lost on its way to the server logs and the RPC response to the client.

For example, a partially written app is missing some required string property (doesn't matter which one) on a JSON request; this code in RpcHandler.java is reached in openvidu-server:

if (request.getParams() == null || request.getParams().get(key) == null) {
    throw new RuntimeException("Request element '" + key + "' is missing in method '" + request != null
            ? request.getMethod()
            : "[NO REQUEST OBJECT]"
                    + "'. Check that 'openvidu-server' AND 'openvidu-browser' versions are compatible with each other");
}

But the message "Request element '' is missing in method [...]" does not show up in either the server logs or the response to the client's RPC request.

Expected behavior

When an Exception is thrown from openvidu-server, its message should show up in logs and be used as information added to the RPC response to the client (like the message field of "error" type responses).

In the example, the message "Request element '' is missing in method [...]" should appear in the server logs, and in the message property of the RPC error response.

Wrong current behavior

The logs only contain a stack trace, without the informative message. The RPC response only contains the exception name.

Following the same example, assume a joinRoom call without the session parameter. The server log looks like this:

[ERROR] 2022-06-06 14:54:11,193 [SessionHandler-1m8ll3tni6j3ad0pe1javv5568-e75-t0] org.kurento.jsonrpc.internal.JsonRpcHandlerManager - Exception while processing request {"id":1,"method":"joinRoom","params":{"token":"wss://call-next.openvidu.io?sessionId=SessionA&token=tok_V38n5999VUBaMWhm&edition=pro&webrtcStatsInterval=30&sendBrowserLogs=debug_app","platform":"Chrome 102.0.5005.61 on Linux 64-bit","sdkVersion":"2.22.0","metadata":"","secret":"","recorder":false},"jsonrpc":"2.0"}
java.lang.RuntimeException: joinRoom
   at io.openvidu.server.rpc.RpcHandler.getStringParam(RpcHandler.java:811)
   at io.openvidu.server.rpc.RpcHandler.joinRoom(RpcHandler.java:193)
   at io.openvidu.server.rpc.RpcHandler.handleRequest(RpcHandler.java:126)
   at org.kurento.jsonrpc.internal.JsonRpcHandlerManager.handleRequest(JsonRpcHandlerManager.java:142)
   at org.kurento.jsonrpc.internal.server.ProtocolManager$3.run(ProtocolManager.java:218)
   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   at java.base/java.lang.Thread.run(Thread.java:829)

And the RPC response sent to the client looks like this:

{
  "id": 2,
  "jsonrpc": 2.0,
  "error": {
    "code": -1,
    "message": "java.lang.RuntimeException:joinRoom",
    "data": "java.lang.RuntimeException: joinRoom\n\tat io.openvidu.server.rpc.RpcHandler.getStringParam(RpcHandler.java:811)\n\tat io.openvidu.server.rpc.RpcHandler.joinRoom(RpcHandler.java:193)\n\tat io.openvidu.server.rpc.RpcHandler.handleRequest(RpcHandler.java:126)\n\tat org.kurento.jsonrpc.internal.JsonRpcHandlerManager.handleRequest(JsonRpcHandlerManager.java:142)\n\tat org.kurento.jsonrpc.internal.server.ProtocolManager$3.run(ProtocolManager.java:218)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n"
  }
}

OpenVidu tutorial where to replicate the error

OpenVidu deployment info

Tested with master tutorial and master OpenVidu server.

Client device info (if applicable)

Affects any implementation of the RPC, including official SDKs.

Screenshots

Additional context

This seems to happen on several server Exceptions. The example shown here is just that, an example, not an exhaustive list.

I don't have reasons to believe the same problem doesn't happen for all other of the get*Param methods in RpcHandler.java.

Also, the same issue has been found for other errors, such as this error in KurentoParticipant.java:

if (subscriber.getEndpoint() == null) {
    throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE,
            "Unable to create subscriber endpoint");
}

So it seems clear that this is a problem in some higher-level logic that catches the exceptions but doesn't use their messages to generate user-visible error strings.

pabloFuente commented 2 years ago

Fixed by https://github.com/OpenVidu/openvidu/commit/83397b07dc8b5318edc1356a91631a471fd08ea9