apache/beam · error
expected 1 option, got
Error message
expected 1 option, got %v: %v
What it means
Error returned by the element-wise sampler hook's Init function when the hook was configured with more than one option string. The sampler hook accepts exactly zero or one option (a duration like '500ms' controlling the sample period), so a longer option list is rejected before time.ParseDuration runs.
Solutions
- Pass exactly one duration string, e.g. "10s".
- Strip extra comma/space-separated values from the option.
- Omit the option entirely to disable sampling (len==0 accepted).
Example fix
// before --sampler_frequency="10s,60s" // after --sampler_frequency="10s"
Defensive patterns
Strategy: validation
Validate before calling
opts := strings.Split(samplerOpt, ",")
if len(opts) > 1 { return fmt.Errorf("sampler hook takes at most 1 option, got %d", len(opts)) }
if len(opts) == 1 { if _, err := time.ParseDuration(opts[0]); err != nil { return err } } Try / catch
if err := hook.Init(ctx); err != nil {
log.Fatalf("sampler hook option error: %v", err)
} Prevention
- Supply a single Go duration string like "10s".
- Do not append extra values or trailing separators.
When it happens
Trigger: Configuring the sampler hook (sampler_frequency style options) with multiple values, e.g. "10s,5s", or an option string with stray separators creating more than one opt.
Common situations: Copy-pasted flag values with extra arguments, or runners emitting deprecated multi-value formats no longer accepted by the SDK.
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 2 options, 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/3fccfeeb61b501f9.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/harness/sampler_hook.go:38
"fmt"
"time"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks"
)
var (
samplePeriod time.Duration = 200 * time.Millisecond
)
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) > 1 {
return ctx, fmt.Errorf("expected 1 option, got %v: %v", len(opts), opts)
}
sampleTime, err := time.ParseDuration(opts[0])
if err != nil {
return nil, err
}
samplePeriod = sampleTime
return ctx, nil
},
}
}
hooks.RegisterHook("beam:go:hook:dofnmetrics:sampletime", hf)
}
View on GitHub (pinned to 12126d8942)