{"id":"6ecb4618293a146c","repo":"go-sql-driver/mysql","slug":"default-addr-for-network-cfg-net-unknown","errorCode":null,"errorMessage":"default addr for network '{cfg.Net}' unknown","messagePattern":"default addr for network '(.+?)' unknown","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dsn.go","lineNumber":190,"sourceCode":"func (cfg *Config) normalize() error {\n\tif cfg.InterpolateParams && cfg.Collation != \"\" && unsafeCollations[cfg.Collation] {\n\t\treturn errInvalidDSNUnsafeCollation\n\t}\n\n\t// Set default network if empty\n\tif cfg.Net == \"\" {\n\t\tcfg.Net = \"tcp\"\n\t}\n\n\t// Set default address if empty\n\tif cfg.Addr == \"\" {\n\t\tswitch cfg.Net {\n\t\tcase \"tcp\":\n\t\t\tcfg.Addr = \"127.0.0.1:3306\"\n\t\tcase \"unix\":\n\t\t\tcfg.Addr = \"/tmp/mysql.sock\"\n\t\tdefault:\n\t\t\treturn errors.New(\"default addr for network '\" + cfg.Net + \"' unknown\")\n\t\t}\n\t} else if cfg.Net == \"tcp\" {\n\t\tcfg.Addr = ensureHavePort(cfg.Addr)\n\t}\n\n\tif cfg.TLS == nil {\n\t\tswitch cfg.TLSConfig {\n\t\tcase \"false\", \"\":\n\t\t\t// don't set anything\n\t\tcase \"true\":\n\t\t\tcfg.TLS = &tls.Config{}\n\t\tcase \"skip-verify\":\n\t\t\tcfg.TLS = &tls.Config{InsecureSkipVerify: true}\n\t\tcase \"preferred\":\n\t\t\tcfg.TLS = &tls.Config{InsecureSkipVerify: true}\n\t\t\tcfg.AllowFallbackToPlaintext = true\n\t\tdefault:\n\t\t\tcfg.TLS = getTLSConfigClone(cfg.TLSConfig)","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/dsn.go#L172-L208","documentation":"normalize() auto-fills a default address only for Net=='tcp' (127.0.0.1:3306) and Net=='unix' (/tmp/mysql.sock). For any other Net value with an empty Addr it returns 'default addr for network <net> unknown' at dsn.go:190. Net is case-sensitive, so 'TCP' or 'Unix' are treated as unknown networks.","triggerScenarios":"Config{Net:'udp'}, Config{Net:'TCP'} (wrong case), or a DSN 'user@udp()/db' with no explicit address; any custom net label without an Addr.","commonSituations":"Case typo ('TCP' instead of 'tcp'); a custom DialFunc with a non-standard net label but Addr left blank; misreading docs that capitalize 'TCP'.","solutions":["Use lowercase 'tcp' or 'unix' for Net.","If you genuinely need a non-standard net label, set cfg.Addr explicitly (or put (addr) in the DSN) so normalize() does not need a default.","Check Net spelling/case against the two accepted values before opening."],"exampleFix":"// before\ncfg := mysql.NewConfig()\ncfg.Net = \"TCP\" // wrong case\ncfg.DBName = \"db\"\n// after\ncfg.Net = \"tcp\" // or \"unix\"","handlingStrategy":"validation","validationCode":"func validNet(net, addr string) bool {\n    if addr != \"\" { return true }\n    return net == \"tcp\" || net == \"unix\"\n}","typeGuard":null,"tryCatchPattern":"if _, err := mysql.ParseDSN(dsn); err != nil && strings.Contains(err.Error(), \"default addr for network\") {\n    // fix Net case to tcp/unix, or set Addr explicitly\n}","preventionTips":["Use lowercase 'tcp'/'unix' — Net is case-sensitive.","Always set Addr explicitly when using a non-standard net label.","Unit-test the config builder to assert Net is one of the two accepted values."],"tags":["go","mysql","dsn","network","config"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}