{"record":{"id":"118d0d622701eabe","repo":"yudai/gotty","slug":"failed-to-authenticate-websocket-connection-inval","errorCode":null,"errorMessage":"failed to authenticate websocket connection: invalid message type","messagePattern":"failed to authenticate websocket connection: invalid message type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/handlers.go","lineNumber":96,"sourceCode":"\t\tcase ctx.Err():\n\t\t\tcloseReason = \"cancelation\"\n\t\tcase webtty.ErrSlaveClosed:\n\t\t\tcloseReason = server.factory.Name()\n\t\tcase webtty.ErrMasterClosed:\n\t\t\tcloseReason = \"client\"\n\t\tdefault:\n\t\t\tcloseReason = fmt.Sprintf(\"an error: %s\", err)\n\t\t}\n\t}\n}\n\nfunc (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) error {\n\ttyp, initLine, err := conn.ReadMessage()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to authenticate websocket connection\")\n\t}\n\tif typ != websocket.TextMessage {\n\t\treturn errors.New(\"failed to authenticate websocket connection: invalid message type\")\n\t}\n\n\tvar init InitMessage\n\terr = json.Unmarshal(initLine, &init)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to authenticate websocket connection\")\n\t}\n\tif init.AuthToken != server.options.Credential {\n\t\treturn errors.New(\"failed to authenticate websocket connection\")\n\t}\n\n\tqueryPath := \"?\"\n\tif server.options.PermitArguments && init.Arguments != \"\" {\n\t\tqueryPath = init.Arguments\n\t}\n\n\tquery, err := url.Parse(queryPath)\n\tif err != nil {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/yudai/gotty/blob/a080c85cbc59226c94c6941ad8c395232d72d517/server/handlers.go#L78-L114","documentation":"Guard in processWSConn rejecting the auth handshake because the first message arrived as a binary (or non-text) websocket frame instead of the expected TextMessage carrying the JSON credentials. The fault is the client's framing, not the payload contents.","triggerScenarios":"Thrown at server/handlers.go:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the client sends its auth JSON as a websocket text frame, not binary","Upgrade client libraries that default to binary frames (e.g. some Go/JS ws configs)","Close the connection with a policy-violation close code so the client can self-correct"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a080c85cbc59226c94c6941ad8c395232d72d517","analyzedAt":"2026-09-02T16:42:38.150Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}