{"record":{"id":"f6a12e7b3ee4dd77","repo":"quarkusio/quarkus","slug":"onerror-callback-on-websocketclient-must-not-acc","errorCode":null,"errorMessage":"@OnError callback on @WebSocketClient must not accept WebSocketConnection: ","messagePattern":"@OnError callback on @WebSocketClient must not accept WebSocketConnection: ","errorType":"validation","errorClass":"WebSocketException","httpStatus":null,"severity":"error","filePath":"extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/WebSocketProcessor.java","lineNumber":1841,"sourceCode":"            b0.return_(encodeMessage(endpointThis, b0, callback, globalErrorHandlers, endpoint, result, metricsSupportEnabled));\n        }\n    }\n\n    static List<Callback> findErrorHandlers(Target expectedTarget, IndexView index, BeanInfo bean, ClassInfo beanClass,\n            CallbackArgumentsBuildItem callbackArguments, TransformedAnnotationsBuildItem transformedAnnotations,\n            String endpointPath) {\n        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(","sourceCodeStart":1823,"sourceCodeEnd":1859,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/WebSocketProcessor.java#L1823-L1859","documentation":"In websockets-next, @WebSocketClient endpoints must use WebSocketClientConnection, and @WebSocket (server) endpoints must use WebSocketConnection. An @OnError callback declared on a client endpoint that accepts a WebSocketConnection parameter fails the build, since that connection type only exists for server endpoints.","triggerScenarios":"An @WebSocketClient class contains an @OnError method whose parameter list includes io.quarkus.websockets.next.WebSocketConnection instead of WebSocketClientConnection.","commonSituations":"Copy-pasting an error handler from a server endpoint into a client endpoint; IDE auto-import picking the wrong Connection class; refactoring a shared handler class.","solutions":["Replace the WebSocketConnection parameter with WebSocketClientConnection","Fix the import statement to io.quarkus.websockets.next.WebSocketClientConnection","Remove the connection parameter entirely if it is not needed"],"exampleFix":"// before (client endpoint)\n@OnError\nvoid onError(WebSocketConnection conn, Exception e) {}\n\n// after\nimport io.quarkus.websockets.next.WebSocketClientConnection;\n@OnError\nvoid onError(WebSocketClientConnection conn, Exception e) {}\n","handlingStrategy":"validation","validationCode":"// In a @WebSocketClient class, ensure error handlers use WebSocketClientConnection\n@OnError void onError(WebSocketClientConnection conn, Throwable t) {}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Client endpoints always use WebSocketClientConnection","Check imports: io.quarkus.websockets.next.WebSocketClientConnection","When copying server handlers to clients, update the connection type"],"tags":["quarkus","websockets-next","websocket-client","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"}