apache/beam · error

CreateTracker has unexpected number of return values

Error message

CreateTracker has unexpected number of return values: %v

What it means

The reflection invoker for the SDF method CreateTracker expects the method to return an sdf.RTracker, optionally with an error. Any other arity (or a return value that is not an sdf.RTracker) makes the invoker panic, since it must produce a valid restriction tracker for splitting and progress tracking.

Solutions

  1. Return exactly (sdf.RTracker) or (sdf.RTracker, error)
  2. Ensure the returned concrete type fully implements sdf.RTracker (embed sdf.RTrackerBase if needed)
  3. Check the returned value satisfies the interface with a compile-time assertion var _ sdf.RTracker = (*myTracker)(nil)
  4. Test with the direct runner before deploying

Example fix

// before
func (fn *MyDoFn) CreateTracker(r MyRestriction) *myTracker { return &myTracker{r} } // doesn't implement RTracker
// after
func (fn *MyDoFn) CreateTracker(r MyRestriction) (sdf.RTracker, error) {
    return &myTracker{Restriction: r, RTrackerBase: sdf.RTrackerBase{}}, nil
}
Defensive patterns

Strategy: validation

Validate before calling

var _ sdf.RTracker = (*myTracker)(nil)
t := reflect.TypeOf(fn.CreateTracker)
if t.NumOut() != 1 && t.NumOut() != 2 {
    panic("CreateTracker must return (sdf.RTracker) or (sdf.RTracker, error)")
}

Type guard

func returnsRTracker(m interface{}) bool {
    t := reflect.TypeOf(m)
    return t.NumOut() >= 1 && t.Out(0).Implements(reflect.TypeOf((*sdf.RTracker)(nil)).Elem())
}

Prevention

When it happens

Trigger: CreateTracker returning a custom tracker type that does not implement sdf.RTracker; returning (tracker, extraValue); 0 or 3+ return values.

Common situations: Custom trackers that forgot to embed/implement all sdf.RTracker methods (NoRest, TryClaim, etc.); returning a pointer to a type only satisfying part of the interface; signature drift after refactor.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/47ebd270d33c2808. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go:267

			return r0.(sdf.RTracker), asError(r1)
		}

	default:
		if len(n.fn.Param) < 1 || len(n.fn.Param) > 2 {
			return errors.Errorf("CreateTracker has unexpected number of parameters: %v", len(n.fn.Param))
		}

		n.call = func() (rt sdf.RTracker, err error) {
			ret := n.fn.Fn.Call(n.args)

			switch len(ret) {
			case 1:
				return ret[0].(sdf.RTracker), nil
			case 2:
				return ret[0].(sdf.RTracker), asError(ret[1])
			}

			panic(fmt.Sprintf("CreateTracker has unexpected number of return values: %v", len(ret)))
		}
	}

	return nil
}

func (n *trInvoker) initCallFn() error {
	// Expects a signature of the form:
	// (context.Context?, sdf.RTracker, key?, value) (restriction, error?)
	// TODO(BEAM-9643): Link to full documentation.
	switch fnT := n.fn.Fn.(type) {

	case reflectx.Func2x1:
		n.call = func() (rest any, err error) {
			r0 := fnT.Call2x1(n.args[0], n.args[1])
			return r0, nil
		}

View on GitHub (pinned to 12126d8942)