gorilla/mux · error
mux: route doesn't have queries
Error message
mux: route doesn't have queries
What it means
Returned by Route.GetQueriesRegexp (route.go:730-735) when the route has no query matchers (r.regexp.queries == nil). Intended for documentation/instrumentation; returns the compiled regexps of registered .Queries(...) matchers.
Source
Thrown at route.go:735
return "", r.err
}
if r.regexp.path == nil {
return "", errors.New("mux: route does not have a path")
}
return r.regexp.path.regexp.String(), nil
}
// GetQueriesRegexp returns the expanded regular expressions used to match the
// route queries.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not have queries.
func (r *Route) GetQueriesRegexp() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {
return nil, errors.New("mux: route doesn't have queries")
}
queries := make([]string, 0, len(r.regexp.queries))
for _, query := range r.regexp.queries {
queries = append(queries, query.regexp.String())
}
return queries, nil
}
// GetQueriesTemplates returns the templates used to build the
// query matching.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define queries.
func (r *Route) GetQueriesTemplates() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {View on GitHub (pinned to db9d1d0073)
Solutions
- Treat the error as 'no queries' and skip/nil it.
- Use GetQueriesTemplates for the raw templates.
- Filter to query-bearing routes.
Example fix
// before
qs, err := route.GetQueriesRegexp()
// after
qs, err := route.GetQueriesRegexp()
if err != nil { qs = nil } Defensive patterns
Strategy: try-catch
Validate before calling
qs, err := route.GetQueriesRegexp()
if err != nil { qs = nil } Type guard
func hasQueries(rt *mux.Route) bool { _, err := rt.GetQueriesRegexp(); return err == nil } Try / catch
qs, err := rt.GetQueriesRegexp()
if err != nil { qs = nil } Prevention
- Treat the error as 'no queries'.
- Defensive introspection.
- Document query-bearing routes.
When it happens
Trigger: Calling GetQueriesRegexp() on a route that never had .Queries(...) called.
Common situations: Docs/metrics iterating all routes; routes that match path but not query.
Related errors
- mux: route does not have a path
- mux: route doesn't have methods
- mux: number of parameters must be multiple of 2, got %v
- method is not allowed
- no matching route was found
AI-assisted analysis of gorilla/mux@db9d1d0073 (2026-08-04).
Data as JSON: /data/errors/fa49e64c55dc56dc.json.
Report an issue: GitHub.