{"record":{"id":"9ff12c1bf797a70b","repo":"t8y2/dbx","slug":"definition-is-required","errorCode":null,"errorMessage":"definition is required","messagePattern":"definition is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":1059,"sourceCode":"\t}\n}\n\nfunc (s *server) setPolicy(params jsonObject) (any, error) {\n\tvhost, err := permissionVhost(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tname, err := policyName(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tpattern := stringOrEmpty(params, \"pattern\")\n\tif strings.TrimSpace(pattern) == \"\" {\n\t\treturn nil, errors.New(\"pattern is required\")\n\t}\n\tdefinition := objectOrNil(params, \"definition\")\n\tif definition == nil {\n\t\treturn nil, errors.New(\"definition is required\")\n\t}\n\tconnection, err := s.requireConnectionConfig(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tbody := jsonObject{\n\t\t\"pattern\":    pattern,\n\t\t\"apply-to\":   stringOrDefault(params, \"applyTo\", \"queues\"),\n\t\t\"priority\":   intOrDefault(params, \"priority\", 0),\n\t\t\"definition\": definition,\n\t}\n\tif _, err := managementSend(connection, http.MethodPut,\n\t\t\"/api/policies/\"+urlEncodeVhost(vhost)+\"/\"+urlEncodePathSegment(name), body); err != nil {\n\t\treturn nil, err\n\t}\n\treturn okResult(), nil\n}\n","sourceCodeStart":1041,"sourceCodeEnd":1077,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L1041-L1077","documentation":"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.","triggerScenarios":"Dispatching setPolicy with name and pattern but without definition, or definition explicitly null/undefined.","commonSituations":"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.","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"],"exampleFix":"// before\n{ \"op\": \"setPolicy\", \"name\": \"ha\", \"pattern\": \".*\" }\n// after\n{ \"op\": \"setPolicy\", \"name\": \"ha\", \"pattern\": \".*\", \"definition\": { \"ha-mode\": \"all\" } }","handlingStrategy":"validation","validationCode":"if (!params.definition || typeof params.definition !== \"object\") throw new Error(\"definition is required\");","typeGuard":"function hasDefinition(p) { return p.definition != null && typeof p.definition === \"object\" && !Array.isArray(p.definition); }","tryCatchPattern":"try { await agent.dispatch(\"setPolicy\", params); } catch (e) { if (/definition is required/.test(e.message)) { /* supply policy definition object and retry */ } else throw e; }","preventionTips":["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"],"tags":["rabbitmq","parameter-validation","policy"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}