apache/beam · error
expected 2 options, got
Error message
expected 2 options, got %v: %v
What it means
The diagnostics hook's Init expects exactly two options: heapProfileSamplingFrequencySeconds and another sampling frequency. Any option count other than 0 or 2 produces this error listing the count and values received.
Solutions
- Pass exactly two integer options: heap profile and goroutine profile sampling frequencies in seconds, e.g. "30,30".
- Remove trailing commas or whitespace that can split into extra options.
- Leave options empty to disable the hook (len==0 accepted).
- Verify the runner's flag construction matches the current SDK hook option format.
Example fix
// before --diagnostics_sampling_frequency="30" // after --diagnostics_sampling_frequency="30,30"
Defensive patterns
Strategy: validation
Validate before calling
opts := strings.Split(diagOpt, ",")
if len(opts) != 2 { return fmt.Errorf("diagnostics hook needs exactly 2 options, got %d", len(opts)) }
for _, o := range opts { if _, err := strconv.Atoi(strings.TrimSpace(o)); err != nil { return err } } Try / catch
if err := hook.Init(ctx); err != nil {
log.Fatalf("diagnostics hook option error: %v", err)
} Prevention
- Always supply both sampling frequencies as a comma pair.
- Avoid trailing commas in option strings.
- Match the option format to your SDK version's hook spec.
When it happens
Trigger: Configuring the diagnostics hook (diagnostics_sampling_frequency style options) with 1 or 3+ values, e.g. only "30" without the second frequency, or trailing separators producing extra empty options.
Common situations: Workers launched with incomplete option strings, trailing commas, or format changes between Beam versions that altered the expected option count.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- expected 1 option, got
- expected 1 option, got
- max time between dumps
- sample period should be greater than 1ms, got
- bad coder kind
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/22a71dc0111f6146.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/harness/diagnostics_hook.go:39
"strconv"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks"
)
var (
samplingFrequencySeconds int = 1
maxTimeBetweenDumpsSeconds int = 60
)
func init() {
hf := func(opts []string) hooks.Hook {
return hooks.Hook{
Init: func(ctx context.Context) (context.Context, error) {
if len(opts) == 0 {
return ctx, nil
}
if len(opts) < 2 || len(opts) > 2 {
return ctx, fmt.Errorf("expected 2 options, got %v: %v", len(opts), opts)
}
heapProfileSamplingFrequencySeconds, err := strconv.Atoi(opts[0])
if err != nil {
return nil, err
}
heapProfileMaxTimeBetweenDumpsSeconds, err := strconv.Atoi(opts[1])
if err != nil {
return nil, err
}
samplingFrequencySeconds = heapProfileSamplingFrequencySeconds
maxTimeBetweenDumpsSeconds = heapProfileMaxTimeBetweenDumpsSeconds
return ctx, nil
},
}
}
hooks.RegisterHook("beam:go:hook:diagnostics:heapDump", hf)View on GitHub (pinned to 12126d8942)