{"id":"e20f43b65dff53f4","repo":"jackc/pgx","slug":"config-must-be-created-by-parseconfig-e20f43","errorCode":null,"errorMessage":"config must be created by ParseConfig","messagePattern":"config must be created by ParseConfig","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/pgconn.go","lineNumber":147,"sourceCode":"\tconfig, err := ParseConfigWithOptions(connString, parseConfigOptions)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn ConnectConfig(ctx, config)\n}\n\n// Connect establishes a connection to a PostgreSQL server using config. config must have been constructed with\n// [ParseConfig]. ctx can be used to cancel a connect attempt.\n//\n// If config.Fallbacks are present they will sequentially be tried in case of error establishing network connection. An\n// authentication error will terminate the chain of attempts (like libpq:\n// https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS) and be returned as the error.\nfunc ConnectConfig(ctx context.Context, config *Config) (*PgConn, error) {\n\t// Default values are set in ParseConfig. Enforce initial creation by ParseConfig rather than setting defaults from\n\t// zero values.\n\tif !config.createdByParseConfig {\n\t\tpanic(\"config must be created by ParseConfig\")\n\t}\n\n\tvar allErrors []error\n\n\tconnectConfigs, errs := buildConnectOneConfigs(ctx, config)\n\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}","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/pgconn.go#L129-L165","documentation":"Error \"config must be created by ParseConfig\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgconn/pgconn.go:147 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}