apache/beam · error
RestrictionSize has unexpected number of return values
Error message
RestrictionSize has unexpected number of return values: %v
What it means
The reflection invoker for the SDF method RestrictionSize requires the method to return a float64 size, optionally paired with an error. If the reflected invocation returns any other number of values, the runtime cannot extract the size and panics with this message. The float64 type assertion in the source shows the contract is strict about both arity and type.
Solutions
- Return exactly float64 (e.g. r.Size(elem) float64)
- Optionally return (float64, error) — keep the size first
- Cast internal size computations to float64 before returning
- Re-verify with a unit test calling the invoker path
Example fix
// before
func (fn *MyDoFn) RestrictionSize(r MyRestriction, elem string) int { return int(r.End - r.Start) }
// after
func (fn *MyDoFn) RestrictionSize(r MyRestriction, elem string) (float64, error) { return r.End - r.Start, nil } Defensive patterns
Strategy: validation
Validate before calling
t := reflect.TypeOf(fn.RestrictionSize)
if t.NumOut() != 1 && t.NumOut() != 2 {
panic("RestrictionSize must return (float64) or (float64, error)")
} Type guard
func validSizeOut(m interface{}) bool {
t := reflect.TypeOf(m)
return t.NumOut() >= 1 && t.Out(0).Kind() == reflect.Float64
} Prevention
- Always use float64 for restriction sizes, never int
- Cast computed sizes: return float64(r.End - r.Start)
- Add a unit test invoking RestrictionSize through the invoker
- Follow the sdf package's canonical RestrictionSize examples
When it happens
Trigger: RestrictionSize returning int instead of float64 (type assertion failure path) or with 0/3+ returns; a method registered as RestrictionSize that actually computes something else.
Common situations: Using Go's natural int for sizes; updating the method to return a struct or percentage alongside the size; porting code from other SDKs (Python/Java) with different size conventions.
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
- coder type must be identical to node type
- CreateInitialRestriction has unexpected number of return…
- CreateTracker has unexpected number of parameters
- CreateTracker has unexpected number of return values
- emit parameter in method
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/fabfcaa6e58669b0.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go:215
return r0.(float64), asError(r1)
}
default:
if len(n.fn.Param) < 2 || len(n.fn.Param) > 4 {
return errors.Errorf("RestrictionSize has unexpected number of parameters: %v", len(n.fn.Param))
}
n.call = func() (size float64, err error) {
ret := n.fn.Fn.Call(n.args)
switch len(ret) {
case 1:
return ret[0].(float64), nil
case 2:
return ret[0].(float64), asError(ret[1])
}
panic(fmt.Sprintf("RestrictionSize has unexpected number of return values: %v", len(ret)))
}
}
return nil
}
func (n *ctInvoker) initCallFn() error {
// Expects a signature of the form:
// (context.Context?, restriction) (sdf.RTracker, error?)
// TODO(BEAM-9643): Link to full documentation.
switch fnT := n.fn.Fn.(type) {
case reflectx.Func1x1:
n.call = func() (rt sdf.RTracker, err error) {
r0 := fnT.Call1x1(n.args[0])
return r0.(sdf.RTracker), nil
}
View on GitHub (pinned to 12126d8942)