{"record":{"id":"0445d72751d78314","repo":"crowdsecurity/crowdsec","slug":"failed-to-parse-dsn-parameters-w","errorCode":null,"errorMessage":"failed to parse DSN parameters: %w","messagePattern":"failed to parse DSN parameters: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/wineventlog/config_windows.go","lineNumber":211,"sourceCode":"\n\tdsn = strings.TrimPrefix(dsn, \"wineventlog://\")\n\n\targs := strings.Split(dsn, \"?\")\n\n\tif args[0] == \"\" {\n\t\treturn errors.New(\"empty wineventlog:// DSN\")\n\t}\n\n\tif len(args) > 2 {\n\t\treturn errors.New(\"too many arguments in DSN\")\n\t}\n\n\ts.config.EventFile = args[0]\n\n\tif len(args) == 2 && args[1] != \"\" {\n\t\tparams, err := url.ParseQuery(args[1])\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse DSN parameters: %w\", err)\n\t\t}\n\n\t\tfor key, value := range params {\n\t\t\tswitch key {\n\t\t\tcase \"log_level\":\n\t\t\t\tif len(value) != 1 {\n\t\t\t\t\treturn errors.New(\"log_level must be a single value\")\n\t\t\t\t}\n\t\t\t\tlvl, err := log.ParseLevel(value[0])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to parse log_level: %s\", err)\n\t\t\t\t}\n\t\t\t\ts.logger.Logger.SetLevel(lvl)\n\t\t\tcase \"event_id\":\n\t\t\t\tfor _, id := range value {\n\t\t\t\t\tevtid, err := strconv.Atoi(id)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"failed to parse event_id: %s\", err)","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/wineventlog/config_windows.go#L193-L229","documentation":"After splitting the DSN into the channel/file part and an optional query-string part, ConfigureByDSN parses the parameters with url.ParseQuery. This error wraps a failure of that parsing — the parameter section after `?` is not a valid URL-encoded query string (e.g. a stray `%` or malformed escape sequence).","triggerScenarios":"A DSN like `wineventlog://Security?event_id=4625%` where the percent-encoding is malformed, or parameters containing characters url.ParseQuery cannot decode (invalid hex after %, missing = in odd spots producing errors per its rules).","commonSituations":"Hand-written DSNs with unescaped special characters, copy-paste mangling (e.g. `&` handling from URLs), or generating DSNs without url.Values.Encode().","solutions":["Fix the malformed percent-encoding in the DSN — e.g. `%` must be followed by two hex digits.","Build the parameter section with net/url: `url.Values{\"event_id\": []string{\"4624\"}}.Encode()` and append after `?`.","URL-escape special characters (&, =, %) that appear in parameter values.","Simplify: omit the `?params` section entirely if no parameters are needed."],"exampleFix":"// before\ndsn := \"wineventlog://Security?event_id=4625%&level=error\"\n// after\nparams := url.Values{}\nparams.Add(\"event_id\", \"4625\")\nparams.Add(\"level\", \"error\")\ndsn := \"wineventlog://Security?\" + params.Encode()","handlingStrategy":"validation","validationCode":"params := url.Values{}\nparams.Add(\"event_id\", \"4625\")\ndsn := \"wineventlog://Security?\" + params.Encode() // Encode guarantees parseability","typeGuard":null,"tryCatchPattern":"if _, err := url.ParseQuery(strings.SplitN(dsn, \"?\", 2)[1]); err != nil {\n\treturn fmt.Errorf(\"malformed DSN parameters: %w\", err)\n}","preventionTips":["Always construct parameter sections with url.Values.Encode()","Never paste parameter strings from browser URLs without re-encoding","Unit-test any DSN-builder function against url.ParseQuery"],"tags":["dsn","url","parsing"],"backgroundTag":"invalid-query-parameter","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}