{"id":"32e1630a34b27109","repo":"jackc/pgx","slug":"afterconnect-error-w","errorCode":null,"errorMessage":"AfterConnect error: %w","messagePattern":"AfterConnect error: %w","errorType":"exception","errorClass":"ConnectError","httpStatus":null,"severity":"error","filePath":"pgconn/pgconn.go","lineNumber":171,"sourceCode":"\tif len(errs) > 0 {\n\t\tallErrors = append(allErrors, errs...)\n\t}\n\n\tif len(connectConfigs) == 0 {\n\t\treturn nil, &ConnectError{Config: config, err: fmt.Errorf(\"hostname resolving error: %w\", errors.Join(allErrors...))}\n\t}\n\n\tpgConn, errs := connectPreferred(ctx, config, connectConfigs)\n\tif len(errs) > 0 {\n\t\tallErrors = append(allErrors, errs...)\n\t\treturn nil, &ConnectError{Config: config, err: errors.Join(allErrors...)}\n\t}\n\n\tif config.AfterConnect != nil {\n\t\terr := config.AfterConnect(ctx, pgConn)\n\t\tif err != nil {\n\t\t\tpgConn.conn.Close()\n\t\t\treturn nil, &ConnectError{Config: config, err: fmt.Errorf(\"AfterConnect error: %w\", err)}\n\t\t}\n\t}\n\n\treturn pgConn, nil\n}\n\n// buildConnectOneConfigs resolves hostnames and builds a list of connectOneConfigs to try connecting to. It returns a\n// slice of successfully resolved connectOneConfigs and a slice of errors. It is possible for both slices to contain\n// values if some hosts were successfully resolved and others were not.\nfunc buildConnectOneConfigs(ctx context.Context, config *Config) ([]*connectOneConfig, []error) {\n\t// Simplify usage by treating primary config and fallbacks the same.\n\tfallbackConfigs := []*FallbackConfig{\n\t\t{\n\t\t\tHost:      config.Host,\n\t\t\tPort:      config.Port,\n\t\t\tTLSConfig: config.TLSConfig,\n\t\t},\n\t}","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/pgconn.go#L153-L189","documentation":"Error \"AfterConnect error: %w\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgconn/pgconn.go:171 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}