Need help in understanding a websocket error with Akka HTTP 10.5.2 and Scala 3

I got the following runtime exception. But I can’t see where Predef$.require is used in Handshake.
Any tips?

java.lang.IllegalArgumentException: requirement failed: Tried to choose invalid subprotocol ‘Some(json)’ which wasn’t offered by the client: []
	at scala.Predef$.require(Predef.scala:337)
	at akka.http.impl.engine.ws.Handshake$Server$$anon$1.handle(Handshake.scala:120)
	at akka.http.impl.engine.ws.Handshake$Server$$anon$1.handleMessages(Handshake.scala:128)
	at $mycode

where $mycode contains

val upgrade: WebSocketUpgrade = ???
val selectedProtocol: String = ???

upgrade..handleMessages(
       Flow.fromSinkAndSourceCoupled(sink, source),
      Some(selectedProtocol)
   )
1 Like

The file hasn’t changed in many years beyond copyright headers, so that’s current.

The functions and values in Predef are implicitly imported into every Scala file. In this case, require is validating that, if a subProtocol is specified ("json" in this case), it’s one of the protocols sent by the client in the Sec-WebSocket-Protocol header; in this case the client sent no protocols in that header.

The protocol names are arbitrary; as long as the client and server agree, all is well. However json is not one of already-registered websocket subprotocols

1 Like

Hi @leviramsey, thanks for the explanation!

I was looking at Handshake in Akka without realizing that Akka HTTP has a separate repo…

1 Like