t8y2/dbx · error
definition is required
Error message
definition is required
What it means
setPolicy requires a definition object containing the policy settings (e.g. ha-mode, max-length, alternate-exchange). The library throws this when the definition param is absent or null, since a policy with no definition is meaningless to the RabbitMQ management API.
Source
Thrown at agents/drivers/rabbitmq/operations.go:1059
}
}
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, err
}
return okResult(), nil
}
View on GitHub (pinned to c0390bff16)
Solutions
- Pass definition as a JSON object, e.g. {"ha-mode":"all"} or {"max-length":10000}
- Ensure the value is an object, not a JSON-encoded string
- Validate with typeof/is-map before calling
Example fix
// before
{ "op": "setPolicy", "name": "ha", "pattern": ".*" }
// after
{ "op": "setPolicy", "name": "ha", "pattern": ".*", "definition": { "ha-mode": "all" } } Defensive patterns
Strategy: validation
Validate before calling
if (!params.definition || typeof params.definition !== "object") throw new Error("definition is required"); Type guard
function hasDefinition(p) { return p.definition != null && typeof p.definition === "object" && !Array.isArray(p.definition); } Try / catch
try { await agent.dispatch("setPolicy", params); } catch (e) { if (/definition is required/.test(e.message)) { /* supply policy definition object and retry */ } else throw e; } Prevention
- Pass definition as a plain object, never a JSON string
- Pair every policy pattern with its definition in templates
- Validate object-ness of nested params before dispatch
When it happens
Trigger: Dispatching setPolicy with name and pattern but without definition, or definition explicitly null/undefined.
Common situations: Building params dynamically where definition JSON failed to parse; forgetting the object wrapper (passing a string); partial automation scripts updated to add pattern but not definition.
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
- pattern 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/9ff12c1bf797a70b.
Report an issue: GitHub.