{"id":"12af9f9a527b383d","repo":"go-sql-driver/mysql","slug":"invalid-connectionattributes-value-v","errorCode":null,"errorMessage":"invalid connectionAttributes value: %v","messagePattern":"invalid connectionAttributes value: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dsn.go","lineNumber":682,"sourceCode":"\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\":\n\t\t\tconnectionAttributes, err := url.QueryUnescape(value)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid connectionAttributes value: %v\", err)\n\t\t\t}\n\t\t\tcfg.ConnectionAttributes = connectionAttributes\n\n\t\tdefault:\n\t\t\t// lazy init\n\t\t\tif cfg.Params == nil {\n\t\t\t\tcfg.Params = make(map[string]string)\n\t\t\t}\n\n\t\t\tif cfg.Params[key], err = url.QueryUnescape(value); err != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\treturn\n}\n","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/dsn.go#L664-L700","documentation":"Returned when the `connectionAttributes` DSN parameter fails url.QueryUnescape. Connection attributes are key:value pairs sent during the handshake; the driver unescapes the whole value at dsn.go:680. Malformed percent-encoding aborts parsing with this error at dsn.go:682.","triggerScenarios":"DSN contains `connectionAttributes=...` with a bad percent sequence, e.g. `connectionAttributes=attr1:/unescaped/value` (the `/` is fine but a stray `%` is not) or `connectionAttributes=app:v1%2`. The unescape at dsn.go:680 fails and the error is returned at dsn.go:682.","commonSituations":"Embedding version strings or file paths that contain `%` without encoding; building the attributes string by hand; a value like `100%` left unescaped.","solutions":["URL-encode the whole attributes value with url.QueryEscape when building the DSN: e.g. url.QueryEscape(\"program_name:myapp,program_version:1.0\").","Keep attribute values free of `%` and other reserved characters.","Construct the DSN via Config{ConnectionAttributes:...}.FormatDSN(), which encodes the value for you (dsn.go:331)."],"exampleFix":"// before\nattr := \"app:go-app,coverage:100%\"\ndsn := \"u:p@/db?connectionAttributes=\" + attr\n// after\nattr := \"app:go-app,coverage:100%\"\ndsn := \"u:p@/db?connectionAttributes=\" + url.QueryEscape(attr)","handlingStrategy":"validation","validationCode":"enc := url.QueryEscape(connectionAttributes)\nif _, err := url.QueryUnescape(enc); err != nil {\n    return err\n}\ndsn += \"&connectionAttributes=\" + enc","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set Config.ConnectionAttributes and call FormatDSN (it encodes for you).","Never embed raw '%', '/', or ':'-adjacent specials without encoding.","Validate attribute values before formatting."],"tags":["config","dsn","encoding"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}