{"record":{"id":"cb23f02920e596cb","repo":"temporalio/temporal","slug":"or-requires-at-least-2-predicates-got-v","errorCode":null,"errorMessage":"Or requires at least 2 predicates, got %v","messagePattern":"Or requires at least 2 predicates, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/predicates/or.go","lineNumber":18,"sourceCode":"package predicates\n\nimport (\n\t\"fmt\"\n)\n\ntype (\n\tOrImpl[T any] struct {\n\t\t// TODO: see if we can somehow order arbitrary predicats and store a sorted list\n\t\tPredicates []Predicate[T]\n\t}\n)\n\nfunc Or[T any](\n\tpredicates ...Predicate[T],\n) Predicate[T] {\n\tif len(predicates) < 2 {\n\t\tpanic(fmt.Sprintf(\"Or requires at least 2 predicates, got %v\", len(predicates)))\n\t}\n\n\tflattened := make([]Predicate[T], 0, len(predicates))\n\tfor _, p := range predicates {\n\t\tswitch p := p.(type) {\n\t\tcase *OrImpl[T]:\n\t\t\tflattened = appendPredicates(flattened, p.Predicates...)\n\t\tcase *UniversalImpl[T]:\n\t\t\treturn p\n\t\tcase *EmptyImpl[T]:\n\t\t\tcontinue\n\t\tdefault:\n\t\t\tflattened = appendPredicates(flattened, p)\n\t\t}\n\t}\n\n\tswitch len(flattened) {\n\tcase 0:","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/predicates/or.go#L1-L36","documentation":"The Or() constructor in common/predicates builds an OR-composed Predicate from 2+ sub-predicates. It panics when fewer than 2 predicates are given, since OR of 0/1 predicates is not a valid construction in this API.","triggerScenarios":"Calling Or() or Or(p) with zero or one Predicate arguments, e.g. Or[string]().","commonSituations":"Constructing OR filters from user-supplied filter lists that may collapse to fewer than 2 entries after deduplication or flattening.","solutions":["Pass at least 2 predicates to Or","For a single predicate, use it directly without wrapping","Guard dynamically built slices: if len < 2, return the single predicate or a defined always-false predicate"],"exampleFix":"// before\npred := predicates.Or(filtered...)\n// after\nvar pred predicates.Predicate[string]\nif len(filtered) == 1 {\n    pred = filtered[0]\n} else if len(filtered) >= 2 {\n    pred = predicates.Or(filtered...)\n}","handlingStrategy":"validation","validationCode":"if len(preds) < 2 {\n    // handle: use preds[0] directly or a defined always-false predicate\n    return preds[0]\n}\npred := predicates.Or(preds...)","typeGuard":null,"tryCatchPattern":"func safeOr[T any](ps ...predicates.Predicate[T]) (p predicates.Predicate[T]) {\n    defer func() {\n        if recover() != nil { p = fallbackPredicate[T]() }\n    }()\n    return predicates.Or(ps...)\n}","preventionTips":["Check len(predicates) before calling Or","Collapse single-element lists to the bare predicate","Never spread possibly-empty slices into Or"],"tags":["go","panic","predicates","argument-validation"],"backgroundTag":"insufficient-arguments-panic","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}