apache/beam · error

unexpected number of params in method %v. got: %v, want: %v

Error message

unexpected number of params in method %v. got: %v, want: %v or optionally %v if first param is of type context.Context

What it means

validateSdfSigNumbers checks that each required SDF method (e.g. CreateInitialRestriction, SplitRestriction, RestrictionSize, CreateTracker, ProcessElement) has an expected number of parameters; one extra leading context.Context parameter is tolerated. This error is thrown when a method's total parameter count is neither reqParamNum nor reqParamNum+1 with a leading context.Context.

Source

Thrown at sdks/go/pkg/beam/core/graph/fn.go:956

		splitRestrictionName:         num + 1,
		restrictionSizeName:          num + 1,
		createTrackerName:            1,
		truncateRestrictionName:      num + 1,
	}
	optionalSdfs := map[string]bool{
		truncateRestrictionName: true,
	}
	reqReturnNum := 1

	for _, name := range sdfNames {
		method, ok := fn.methods[name]
		if !ok && optionalSdfs[name] {
			continue
		}

		reqParamNum := reqParamNums[name]
		if !sdfHasValidParamNum(method.Param, reqParamNum) {
			err := errors.Errorf("unexpected number of params in method %v. got: %v, want: %v or optionally %v "+
				"if first param is of type context.Context", name, len(method.Param), reqParamNum, reqParamNum+1)
			return errors.SetTopLevelMsgf(err, "Unexpected number of parameters in method %v. "+
				"Got: %v, Want: %v or optionally %v if first param is of type context.Context. "+
				"Check that the signature conforms to the expected signature for %v, and that elements in SDF method "+
				"parameters match elements in %v.", name, len(method.Param), reqParamNum, reqParamNum+1,
				name, processElementName)
		}
		if !sdfHasValidReturnNum(method.Ret, reqReturnNum) {
			err := errors.Errorf("unexpected number of returns in method %v. got: %v, want: %v or optionally %v "+
				"if last value is of type error", name, len(method.Ret), reqReturnNum, reqReturnNum+1)
			return errors.SetTopLevelMsgf(err, "Unexpected number of return values in method %v. "+
				"Got: %v, Want: %v or optionally %v if last value is of type error. "+
				"Check that the signature conforms to the expected signature for %v.",
				name, len(method.Ret), reqReturnNum, reqReturnNum+1, name)
		}
	}
	return nil
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Adjust the method so it has exactly the required number of parameters for that SDF role, optionally preceded by one context.Context parameter.
  2. If you added context.Context, confirm it is the FIRST parameter of the method.
  3. For ProcessElement, ensure it takes the RTracker plus the same element (and optional key/value) parameters as CreateInitialRestriction.
  4. Check the reqParamNums table in fn.go for the exact expected count of the method name reported in the error.

Example fix

// before
func (fn *myFn) CreateTracker(r myRestriction, extra int) *myTracker { ... }

// after
func (fn *myFn) CreateTracker(r myRestriction) *myTracker { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Validate param counts (allowing optional leading context.Context) before beam.TrySdf:
func checkParamCount(t reflect.Type, name string, want int) error {
    m, ok := t.MethodByName(name)
    if !ok { return fmt.Errorf("missing method %s", name) }
    n := m.Type.NumIn() - 1
    if n == want || (n == want+1 && m.Type.In(1) == reflect.TypeOf((*context.Context)(nil)).Elem()) {
        return nil
    }
    return fmt.Errorf("%s: got %d params, want %d (+optional ctx)", name, n, want)
}

Prevention

When it happens

Trigger: Declaring an SDF method with too few or too many parameters — e.g. CreateTracker with two params besides context, or ProcessElement missing its restriction-tracker parameter; also passing a non-context type as the extra first parameter.

Common situations: Copying method signatures from Java/Python SDF examples into Go; adding a context.Context not in the leading position; forgetting to add the RTracker param to ProcessElement when adding SDF methods; typos in parameter lists during refactoring.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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