{"record":{"id":"e55e366c6747975d","repo":"t8y2/dbx","slug":"pattern-is-required","errorCode":null,"errorMessage":"pattern is required","messagePattern":"pattern is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/operations.go","lineNumber":1055,"sourceCode":"\t\t\"pattern\":    stringOrEmpty(policy, \"pattern\"),\n\t\t\"applyTo\":    stringOrEmpty(policy, \"apply-to\"),\n\t\t\"priority\":   longOrDefault(policy, \"priority\", 0),\n\t\t\"definition\": definition,\n\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","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/operations.go#L1037-L1073","documentation":"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.","triggerScenarios":"Dispatching setPolicy with name and definition but no pattern, or pattern:\"\" / whitespace.","commonSituations":"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.","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"],"exampleFix":"// before\n{ \"op\": \"setPolicy\", \"name\": \"ha\", \"definition\": { \"ha-mode\": \"all\" } }\n// after\n{ \"op\": \"setPolicy\", \"name\": \"ha\", \"pattern\": \".*\", \"definition\": { \"ha-mode\": \"all\" } }","handlingStrategy":"validation","validationCode":"if (typeof params.pattern !== \"string\" || !params.pattern.trim()) throw new Error(\"pattern is required\");","typeGuard":"function hasPattern(p) { return typeof p.pattern === \"string\" && p.pattern.trim().length > 0; }","tryCatchPattern":"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; }","preventionTips":["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"],"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-14T05:17:10.506Z"}