apache/beam · critical

TruncateRestriction has unexpected number of parameters

Error message

TruncateRestriction has unexpected number of parameters: %v

What it means

This panic comes from the generated SDF invoker code in the Beam Go SDK. A splittable DoFn's TruncateRestriction method must take between 2 and 4 parameters (restriction, element, optional context, optional rest of restriction); anything outside that range cannot be invoked by the generated arity-dispatch code, so the runtime panics.

Solutions

  1. Adjust TruncateRestriction to accept 2-4 parameters, e.g. (restriction, element) optionally plus context/rest params
  2. Consult the SDF truncation API contract in your SDK version and match an accepted signature
  3. If truncation is not needed, remove the method rather than providing a malformed one

Example fix

// before
func (fn *mySDF) TruncateRestriction() myRestriction { ... }
// after
func (fn *mySDF) TruncateRestriction(rest myRestriction, elem myElem) myRestriction { ... }
Defensive patterns

Strategy: validation

Validate before calling

m, ok := reflect.TypeOf(fn).MethodByName("TruncateRestriction")
if ok {
	in := m.Type.NumIn()
	if in < 3 || in > 5 { // receiver + 2-4 params
		return errors.New("TruncateRestriction must take 2-4 parameters")
	}
}

Type guard

func validTruncateRestriction(fn interface{}) bool {
	m, ok := reflect.TypeOf(fn).MethodByName("TruncateRestriction")
	return !ok || (m.Type.NumIn() >= 3 && m.Type.NumIn() <= 5)
}

Prevention

When it happens

Trigger: Defining TruncateRestriction with 0, 1, or 5+ parameters on a splittable DoFn and running the pipeline, causing the default branch of the generated dispatcher to reject the signature.

Common situations: Adding or removing parameters when porting TruncateRestriction between DoFns; hand-writing an SDF with an unusual signature; framework version differences in accepted arities.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

{{range $in := upto 5}}
    {{if gt $out 0}}
    {{if gt $in 1}}
	case reflectx.Func{{$in}}x{{$out}}:
		n.call = func() (rest any, err error) {
			{{mktuplef $out "r%v"}} := fnT.Call{{$in}}x{{$out}}({{mktuplef $in "n.args[%v]"}})
			{{- if eq $out 1}}
			return r0, nil
			{{- else}}
			return r0, asError(r1)
			{{- end}}
		}
	{{end}}
	{{end}}
{{end}}
{{end}}
	default:
		if len(n.fn.Param) < 2 || len(n.fn.Param) > 4 {
			return errors.Errorf("TruncateRestriction has unexpected number of parameters: %v", len(n.fn.Param))
		}

		n.call = func() (rest any, err error) {
			ret := n.fn.Fn.Call(n.args)

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

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

	return nil
}

View on GitHub (pinned to 12126d8942)