{"id":"4a703ca01f8f6687","repo":"go-sql-driver/mysql","slug":"invalid-value-for-tls-config-name-v","errorCode":null,"errorMessage":"invalid value for TLS config name: %v","messagePattern":"invalid value for TLS config name: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dsn.go","lineNumber":661,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t// TLS-Encryption\n\t\tcase \"tls\":\n\t\t\tboolValue, isBool := readBool(value)\n\t\t\tif isBool {\n\t\t\t\tif boolValue {\n\t\t\t\t\tcfg.TLSConfig = \"true\"\n\t\t\t\t} else {\n\t\t\t\t\tcfg.TLSConfig = \"false\"\n\t\t\t\t}\n\t\t\t} else if vl := strings.ToLower(value); vl == \"skip-verify\" || vl == \"preferred\" {\n\t\t\t\tcfg.TLSConfig = vl\n\t\t\t} else {\n\t\t\t\tname, err := url.QueryUnescape(value)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"invalid value for TLS config name: %v\", err)\n\t\t\t\t}\n\t\t\t\tcfg.TLSConfig = name\n\t\t\t}\n\n\t\t// I/O write Timeout\n\t\tcase \"writeTimeout\":\n\t\t\tcfg.WriteTimeout, err = time.ParseDuration(value)\n\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\tcase \"maxAllowedPacket\":\n\t\t\tcfg.MaxAllowedPacket, err = strconv.Atoi(value)\n\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t// Connection attributes\n\t\tcase \"connectionAttributes\":","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/dsn.go#L643-L679","documentation":"Returned by the `tls` DSN parameter handler when the value is neither a bool (true/false), nor skip-verify/preferred, and also fails url.QueryUnescape. In that branch (dsn.go:659-661) the driver treats the value as the name of a custom TLS config registered via RegisterTLSConfig; a malformed percent-encoded value yields this error.","triggerScenarios":"DSN like `?tls=my%2` or `?tls=100%` where the value is not a recognised keyword and contains an invalid percent-escape sequence. The unescape error is wrapped and returned at dsn.go:661.","commonSituations":"Naming a custom TLS config with a `%` and forgetting to encode it; mixing encoded/decoded layers when templating DSNs across config files.","solutions":["Use a simple ASCII name for RegisterTLSConfig (e.g. `custom`) and reference it as `?tls=custom`.","If the name must contain special characters, URL-encode it with url.QueryEscape when building the DSN.","Prefer the Config{TLSConfig:...}.FormatDSN() builder over string concatenation."],"exampleFix":"// before\ndsn := \"u:p@/db?tls=my%config\"\n// after\nmysql.RegisterTLSConfig(\"custom\", tlscfg)\ndsn := \"u:p@/db?tls=custom\"","handlingStrategy":"validation","validationCode":"switch strings.ToLower(v) {\ncase \"true\",\"false\",\"skip-verify\",\"preferred\":\ndefault:\n    if _, err := url.QueryUnescape(v); err != nil {\n        return errors.New(\"tls value is invalid\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use mysql.RegisterTLSConfig once at startup and reference the name in the DSN.","Encode any custom TLS name with url.QueryEscape.","Avoid special characters in TLS config names."],"tags":["config","dsn","tls","encoding"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}