{"id":"bf0bd81d5741e565","repo":"gorilla/mux","slug":"mux-number-of-parameters-must-be-multiple-of-2-g-bf0bd8","errorCode":null,"errorMessage":"mux: number of parameters must be multiple of 2, got %v","messagePattern":"mux: number of parameters must be multiple of 2, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"route.go","lineNumber":469,"sourceCode":"// For example:\n//\n//\tr := mux.NewRouter().NewRoute()\n//\tr.Queries(\"foo\", \"bar\", \"id\", \"{id:[0-9]+}\")\n//\n// The above route will only match if the URL contains the defined queries\n// values, e.g.: ?foo=bar&id=42.\n//\n// If the value is an empty string, it will match any value if the key is set.\n//\n// Variables can define an optional regexp pattern to be matched:\n//\n// - {name} matches anything until the next slash.\n//\n// - {name:pattern} matches the given regexp pattern.\nfunc (r *Route) Queries(pairs ...string) *Route {\n\tlength := len(pairs)\n\tif length%2 != 0 {\n\t\tr.err = fmt.Errorf(\n\t\t\t\"mux: number of parameters must be multiple of 2, got %v\", pairs)\n\t\treturn nil\n\t}\n\tfor i := 0; i < length; i += 2 {\n\t\tif r.err = r.addRegexpMatcher(pairs[i]+\"=\"+pairs[i+1], regexpTypeQuery); r.err != nil {\n\t\t\treturn r\n\t\t}\n\t}\n\n\treturn r\n}\n\n// Schemes --------------------------------------------------------------------\n\n// schemeMatcher matches the request against URL schemes.\ntype schemeMatcher []string\n\nfunc (m schemeMatcher) Match(r *http.Request, match *RouteMatch) bool {","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/gorilla/mux/blob/db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265/route.go#L451-L487","documentation":"Returned directly by Route.Queries (route.go:467-471) when the variadic pairs are odd. Unlike Headers, Queries checks the count itself (not via checkPairs) and returns a nil *Route on top of being a build error, so the caller must capture the return value.","triggerScenarios":"r.Queries(\"foo\", \"bar\", \"id\") (3 args); passing a half-built slice of key/value pairs whose length is odd.","commonSituations":"Editing a Queries call and dropping a value; building pairs dynamically with an odd length; misunderstanding the key,value,key,value contract.","solutions":["Pass an even number of args (key/value pairs).","Validate len(pairs)%2 == 0 before calling.","Capture and nil-check the returned *Route."],"exampleFix":"// before\nrt := r.Queries(\"foo\", \"bar\", \"id\")\n// odd -> returns nil, no matcher added\n\n// after\nrt := r.Queries(\"foo\", \"bar\", \"id\", \"\")","handlingStrategy":"validation","validationCode":"if len(qs)%2 != 0 {\n    return errors.New(\"queries need even key/value pairs\")\n}\nrt := r.Queries(qs...)","typeGuard":"func validQueriesArgs(pairs ...string) bool { return len(pairs)%2 == 0 }","tryCatchPattern":"rt := r.Queries(pairs...)\nif rt == nil { return errors.New(\"Queries rejected the args\") }","preventionTips":["Prefer a wrapper taking a map[string]string.","Always nil-check the returned route.","Static-check arg counts in wrapper helpers."],"tags":["routing","config","query","build-time"],"analyzedSha":"db9d1d0073d27a0a2d9a8c1bc52aa0af4374d265","analyzedAt":"2026-08-04T21:35:47.097Z","schemaVersion":2}