apache/beam · error
Mismatched output type in method %v, return value at index %
Error message
Mismatched output type in method %v, return value at index %v. Got: %v, Want: %v (from method %v).
What it means
The tracker returned by CreateTracker must be the exact same type as the RTracker parameter ProcessElement accepts. This error fires when CreateTracker's return type differs from the tracker parameter type found in ProcessElement, because the framework passes the created tracker directly into ProcessElement.
Source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:1070
if method.Param[startIdx].T != restrictionT {
err := errors.Errorf("mismatched restriction type in method %v, param %v. got: %v, want: %v",
createTrackerName, startIdx, method.Param[startIdx].T, restrictionT)
return errors.SetTopLevelMsgf(err, "Mismatched restriction type in method %v, "+
"parameter at index %v. Got: %v, Want: %v (from method %v). "+
"Ensure that all restrictions in an SDF are the same type.",
createTrackerName, startIdx, method.Param[startIdx].T, restrictionT, createInitialRestrictionName)
}
if !method.Ret[0].T.Implements(rTrackerT) {
err := errors.Errorf("invalid output type in method %v, return %v: %v does not implement sdf.RTracker",
createTrackerName, 0, method.Ret[0].T)
return errors.SetTopLevelMsgf(err, "Invalid output type in method %v, "+
"return value at index %v (type: %v). Output of method %v must implement sdf.RTracker.",
createTrackerName, 0, method.Ret[0].T, createTrackerName)
}
processFn := fn.methods[processElementName]
pos, _ := processFn.RTracker()
if method.Ret[0].T != processFn.Param[pos].T {
err := errors.Errorf("mismatched output type in method %v, return %v: got: %v, want: %v",
createTrackerName, 0, method.Ret[0].T, processFn.Param[pos].T)
return errors.SetTopLevelMsgf(err, "Mismatched output type in method %v, "+
"return value at index %v. Got: %v, Want: %v (from method %v).",
createTrackerName, 0, method.Ret[0].T, processFn.Param[pos].T, processElementName)
}
}
}
rTrackerImplT := fn.methods[createTrackerName].Ret[0].T
for _, name := range optionalSdfNames {
method, ok := fn.methods[name]
if !ok {
continue
}
startIdx := sdfRequiredParamStartIndex(method)
View on GitHub (pinned to 12126d8942)
Solutions
- Make ProcessElement's tracker parameter the exact concrete type returned by CreateTracker.
- Avoid using the sdf.RTracker interface as the ProcessElement parameter type; use the concrete tracker type.
- If you wrapped the tracker (e.g. LockRTracker) in CreateTracker, use the same wrapper type in ProcessElement.
- Compare Got/Want types in the error and align both methods on one tracker type.
Example fix
// before
func (fn *myFn) CreateTracker(r myRestriction) *myTracker { ... }
func (fn *myFn) ProcessElement(t sdf.RTracker, elem string, emit func(string)) error { ... }
// after
func (fn *myFn) CreateTracker(r myRestriction) *myTracker { ... }
func (fn *myFn) ProcessElement(t *myTracker, elem string, emit func(string)) error { ... } Defensive patterns
Strategy: validation
Validate before calling
// Assert CreateTracker return type == ProcessElement tracker param type:
func checkTrackerConsistency(t reflect.Type) error {
ct, _ := t.MethodByName("CreateTracker")
pe, _ := t.MethodByName("ProcessElement")
got := ct.Type.Out(0)
// find tracker param in ProcessElement (first non-ctx param here)
want := pe.Type.In(1)
if got != want {
return fmt.Errorf("CreateTracker returns %v but ProcessElement takes %v", got, want)
}
return nil
} Prevention
- Use the concrete tracker type (not the sdf.RTracker interface) in ProcessElement
- Change CreateTracker and ProcessElement together when changing tracker types
- Keep tracker type as a single named type referenced by both methods
When it happens
Trigger: CreateTracker returning *myTracker while ProcessElement takes an sdf.RTracker interface (or a different concrete tracker type), or the two methods using different concrete tracker implementations.
Common situations: Declaring ProcessElement's tracker param as the sdf.RTracker interface instead of the concrete tracker type; refactoring one method to a LockRTracker wrapper and not the other; multiple trackers defined for one DoFn.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Mismatched restriction type in method %v, parameter at index
- Invalid output type in method %v, return value at index %v.
- invalid number of main input params in method %v. got: %v, w
- unexpected number of params in method %v. got: %v, want: %v
- unexpected number of returns in method %v. got: %v, want: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/97cac4834d975eaa.
Report an issue: GitHub.