{"record":{"id":"3fccfeeb61b501f9","repo":"apache/beam","slug":"expected-1-option-got-v-v-sampler-hook","errorCode":null,"errorMessage":"expected 1 option, got %v: %v","messagePattern":"expected 1 option, got (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/harness/sampler_hook.go","lineNumber":38,"sourceCode":"\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks\"\n)\n\nvar (\n\tsamplePeriod time.Duration = 200 * time.Millisecond\n)\n\nfunc init() {\n\thf := func(opts []string) hooks.Hook {\n\t\treturn hooks.Hook{\n\t\t\tInit: func(ctx context.Context) (context.Context, error) {\n\t\t\t\tif len(opts) == 0 {\n\t\t\t\t\treturn ctx, nil\n\t\t\t\t}\n\t\t\t\tif len(opts) > 1 {\n\t\t\t\t\treturn ctx, fmt.Errorf(\"expected 1 option, got %v: %v\", len(opts), opts)\n\t\t\t\t}\n\n\t\t\t\tsampleTime, err := time.ParseDuration(opts[0])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tsamplePeriod = sampleTime\n\t\t\t\treturn ctx, nil\n\t\t\t},\n\t\t}\n\t}\n\thooks.RegisterHook(\"beam:go:hook:dofnmetrics:sampletime\", hf)\n}\n","sourceCodeStart":20,"sourceCodeEnd":52,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/harness/sampler_hook.go#L20-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasted flag values with extra arguments, or runners emitting deprecated multi-value formats no longer accepted by the SDK.","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)."],"exampleFix":"// before\n--sampler_frequency=\"10s,60s\"\n// after\n--sampler_frequency=\"10s\"","handlingStrategy":"validation","validationCode":"opts := strings.Split(samplerOpt, \",\")\nif len(opts) > 1 { return fmt.Errorf(\"sampler hook takes at most 1 option, got %d\", len(opts)) }\nif len(opts) == 1 { if _, err := time.ParseDuration(opts[0]); err != nil { return err } }","typeGuard":null,"tryCatchPattern":"if err := hook.Init(ctx); err != nil {\n\tlog.Fatalf(\"sampler hook option error: %v\", err)\n}","preventionTips":["Supply a single Go duration string like \"10s\".","Do not append extra values or trailing separators."],"tags":["configuration","hook","argument-count","beam","go"],"backgroundTag":"missing-required-option","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}