temporalio/temporal · error

Or requires at least 2 predicates, got %v

Error message

Or requires at least 2 predicates, got %v

What it means

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.

Source

Thrown at common/predicates/or.go:18

package predicates

import (
	"fmt"
)

type (
	OrImpl[T any] struct {
		// TODO: see if we can somehow order arbitrary predicats and store a sorted list
		Predicates []Predicate[T]
	}
)

func Or[T any](
	predicates ...Predicate[T],
) Predicate[T] {
	if len(predicates) < 2 {
		panic(fmt.Sprintf("Or requires at least 2 predicates, got %v", len(predicates)))
	}

	flattened := make([]Predicate[T], 0, len(predicates))
	for _, p := range predicates {
		switch p := p.(type) {
		case *OrImpl[T]:
			flattened = appendPredicates(flattened, p.Predicates...)
		case *UniversalImpl[T]:
			return p
		case *EmptyImpl[T]:
			continue
		default:
			flattened = appendPredicates(flattened, p)
		}
	}

	switch len(flattened) {
	case 0:

View on GitHub (pinned to bde624efd1)

Solutions

  1. Pass at least 2 predicates to Or
  2. For a single predicate, use it directly without wrapping
  3. Guard dynamically built slices: if len < 2, return the single predicate or a defined always-false predicate

Example fix

// before
pred := predicates.Or(filtered...)
// after
var pred predicates.Predicate[string]
if len(filtered) == 1 {
    pred = filtered[0]
} else if len(filtered) >= 2 {
    pred = predicates.Or(filtered...)
}
Defensive patterns

Strategy: validation

Validate before calling

if len(preds) < 2 {
    // handle: use preds[0] directly or a defined always-false predicate
    return preds[0]
}
pred := predicates.Or(preds...)

Try / catch

func safeOr[T any](ps ...predicates.Predicate[T]) (p predicates.Predicate[T]) {
    defer func() {
        if recover() != nil { p = fallbackPredicate[T]() }
    }()
    return predicates.Or(ps...)
}

Prevention

When it happens

Trigger: Calling Or() or Or(p) with zero or one Predicate arguments, e.g. Or[string]().

Common situations: Constructing OR filters from user-supplied filter lists that may collapse to fewer than 2 entries after deduplication or flattening.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/cb23f02920e596cb. Report an issue: GitHub.