t8y2/dbx · error
pattern is required
Error message
pattern is required
What it means
setPolicy requires a pattern string (the regex a queue/exchange name is matched against to apply the policy). The library throws this when the pattern param is absent or whitespace-only, because a policy without a match pattern can never apply to any resource.
Source
Thrown at agents/drivers/rabbitmq/operations.go:1055
"pattern": stringOrEmpty(policy, "pattern"),
"applyTo": stringOrEmpty(policy, "apply-to"),
"priority": longOrDefault(policy, "priority", 0),
"definition": definition,
}
}
func (s *server) setPolicy(params jsonObject) (any, error) {
vhost, err := permissionVhost(params)
if err != nil {
return nil, err
}
name, err := policyName(params)
if err != nil {
return nil, err
}
pattern := stringOrEmpty(params, "pattern")
if strings.TrimSpace(pattern) == "" {
return nil, errors.New("pattern is required")
}
definition := objectOrNil(params, "definition")
if definition == nil {
return nil, errors.New("definition is required")
}
connection, err := s.requireConnectionConfig(params)
if err != nil {
return nil, err
}
body := jsonObject{
"pattern": pattern,
"apply-to": stringOrDefault(params, "applyTo", "queues"),
"priority": intOrDefault(params, "priority", 0),
"definition": definition,
}
if _, err := managementSend(connection, http.MethodPut,
"/api/policies/"+urlEncodeVhost(vhost)+"/"+urlEncodePathSegment(name), body); err != nil {
return nil, errView on GitHub (pinned to c0390bff16)
Solutions
- Add a pattern regex, e.g. ".*" to match all queues
- Provide a targeted pattern such as "^orders\\." for name-prefixed queues
- Validate params include non-empty pattern before dispatch
Example fix
// before
{ "op": "setPolicy", "name": "ha", "definition": { "ha-mode": "all" } }
// after
{ "op": "setPolicy", "name": "ha", "pattern": ".*", "definition": { "ha-mode": "all" } } Defensive patterns
Strategy: validation
Validate before calling
if (typeof params.pattern !== "string" || !params.pattern.trim()) throw new Error("pattern is required"); Type guard
function hasPattern(p) { return typeof p.pattern === "string" && p.pattern.trim().length > 0; } Try / catch
try { await agent.dispatch("setPolicy", params); } catch (e) { if (/pattern is required/.test(e.message)) { params.pattern = ".*"; await agent.dispatch("setPolicy", params); } else throw e; } Prevention
- Default pattern to ".*" when you intend to match everything
- Keep policy templates with required fields pattern+definition
- Escape regex special chars in resource names used as patterns
When it happens
Trigger: Dispatching setPolicy with name and definition but no pattern, or pattern:"" / whitespace.
Common situations: Config-driven policy provisioning where the pattern field was omitted; YAML/JSON templating that dropped empty strings; misunderstanding pattern as optional like in some RabbitMQ UIs.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- definition is required
- virtual_host is required
- all_vhosts is only supported for list operations
- user name is required
- Not connected. Call connect first.
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/e55e366c6747975d.
Report an issue: GitHub.