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:
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.
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:
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 thesession
parameter. The server log looks like this:And the RPC response sent to the client looks like this:
OpenVidu tutorial where to replicate the error
app.js
and setOPENVIDU_SERVER_URL
andOPENVIDU_SERVER_SECRET
to use any available Openvidu server deployment (I tested with master).Session.prototype.initializeParams
, comment out thesession:
line.OpenVidu deployment info
Tested with
master
tutorial andmaster
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:
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.