{"record":{"id":"2ac829b1df3af822","repo":"quarkusio/quarkus","slug":"onerror-callback-on-websocket-must-not-accept-we","errorCode":null,"errorMessage":"@OnError callback on @WebSocket must not accept WebSocketClientConnection: ","messagePattern":"@OnError callback on @WebSocket must not accept WebSocketClientConnection: ","errorType":"validation","errorClass":"WebSocketException","httpStatus":null,"severity":"error","filePath":"extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/WebSocketProcessor.java","lineNumber":1848,"sourceCode":"        List<AnnotationInstance> annotations = findCallbackAnnotations(index, beanClass, WebSocketDotNames.ON_ERROR);\n        if (annotations.isEmpty()) {\n            return List.of();\n        }\n        List<Callback> errorHandlers = new ArrayList<>(annotations.size());\n        for (AnnotationInstance annotation : annotations) {\n            MethodInfo method = annotation.target().asMethod();\n            Target target;\n            if (method.parameterTypes().stream().map(Type::name).anyMatch(WebSocketDotNames.WEB_SOCKET_CONNECTION::equals)) {\n                target = Target.SERVER;\n                if (expectedTarget == Target.CLIENT) {\n                    throw new WebSocketException(\"@OnError callback on @WebSocketClient must not accept WebSocketConnection: \"\n                            + method.declaringClass() + \".\" + method.name() + \"()\");\n                }\n            } else if (method.parameterTypes().stream().map(Type::name)\n                    .anyMatch(WebSocketDotNames.WEB_SOCKET_CLIENT_CONNECTION::equals)) {\n                target = Target.CLIENT;\n                if (expectedTarget == Target.SERVER) {\n                    throw new WebSocketException(\"@OnError callback on @WebSocket must not accept WebSocketClientConnection: \"\n                            + method.declaringClass() + \".\" + method.name() + \"()\");\n                }\n            } else {\n                target = Target.UNDEFINED;\n            }\n            Callback callback = new Callback(target, annotation, bean, method,\n                    executionModel(method, transformedAnnotations), callbackArguments, transformedAnnotations,\n                    endpointPath, index);\n            long errorArguments = callback.arguments.stream().filter(ca -> ca instanceof ErrorCallbackArgument).count();\n            if (errorArguments != 1) {\n                throw new WebSocketException(\n                        String.format(\"@OnError callback must accept exactly one error parameter; found %s: %s\",\n                                errorArguments, callback.asString()));\n            }\n            errorHandlers.add(callback);\n        }\n        return errorHandlers;\n    }","sourceCodeStart":1830,"sourceCodeEnd":1866,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/WebSocketProcessor.java#L1830-L1866","documentation":"The mirror of error 2665: an @OnError callback on a server-side @WebSocket endpoint must not accept WebSocketClientConnection. The processor infers the callback target from its connection parameter type and rejects a client connection type on a server endpoint with WebSocketException.","triggerScenarios":"An @WebSocket (server) class has an @OnError method accepting io.quarkus.websockets.next.WebSocketClientConnection.","commonSituations":"Copy-pasting from a client endpoint into a server endpoint; wrong auto-import; shared handler base class using the client connection type.","solutions":["Replace WebSocketClientConnection with WebSocketConnection in the parameter list","Fix the import to io.quarkus.websockets.next.WebSocketConnection","Remove the connection parameter if unused"],"exampleFix":"// before (server endpoint)\n@OnError\nvoid onError(WebSocketClientConnection conn, Exception e) {}\n\n// after\nimport io.quarkus.websockets.next.WebSocketConnection;\n@OnError\nvoid onError(WebSocketConnection conn, Exception e) {}\n","handlingStrategy":"validation","validationCode":"// In a @WebSocket (server) class, use WebSocketConnection in @OnError\n@OnError void onError(WebSocketConnection conn, Throwable t) {}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Server endpoints always use WebSocketConnection","Beware IDE auto-import choosing the Client variant","Never share a handler class that references client connection types in server code"],"tags":["quarkus","websockets-next","websocket-server","wrong-parameter-type"],"backgroundTag":"wrong-connection-type","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}