{"record":{"id":"8c7944715991dff7","repo":"jackc/pgx","slug":"unexpected-message-type-during-oauth-auth-t","errorCode":null,"errorMessage":"unexpected message type during OAuth auth: %T","messagePattern":"unexpected message type during OAuth auth: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/auth_oauth.go","lineNumber":65,"sourceCode":"\t\terrResponse := struct {\n\t\t\tStatus              string `json:\"status\"`\n\t\t\tScope               string `json:\"scope\"`\n\t\t\tOpenIDConfiguration string `json:\"openid-configuration\"`\n\t\t}{}\n\t\terr := json.Unmarshal(m.Data, &errResponse)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid OAuth error response from server: %w\", err)\n\t\t}\n\n\t\t// Per RFC 7628 section 3.2.3, we should send a SASLResponse which only contains \\x01.\n\t\t// However, since the connection will be closed anyway, we can skip this\n\t\treturn fmt.Errorf(\"OAuth authentication failed: %s\", errResponse.Status)\n\n\tcase *pgproto3.ErrorResponse:\n\t\treturn ErrorResponseToPgError(m)\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unexpected message type during OAuth auth: %T\", msg)\n\t}\n}\n","sourceCodeStart":47,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/auth_oauth.go#L47-L68","documentation":"The OAuth SASL exchange received a backend message that is neither AuthenticationSASLContinue nor ErrorResponse. This indicates a protocol desynchronization or a non-conforming server/proxy during the OAuth handshake; the message is aborted since no further progress is possible.","triggerScenarios":"Thrown at pgconn/auth_oauth.go:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the %T value in the error to identify which message broke the exchange","Verify you are connecting to a PostgreSQL server (or proxy) that supports OAuth per RFC 7628","Enable tracing to capture the full message stream leading up to the failure","Test against the server directly with psql to confirm OAuth support"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}