{"record":{"id":"22a71dc0111f6146","repo":"apache/beam","slug":"expected-2-options-got-v-v","errorCode":null,"errorMessage":"expected 2 options, got %v: %v","messagePattern":"expected 2 options, got (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/harness/diagnostics_hook.go","lineNumber":39,"sourceCode":"\t\"strconv\"\n\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks\"\n)\n\nvar (\n\tsamplingFrequencySeconds   int = 1\n\tmaxTimeBetweenDumpsSeconds int = 60\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) < 2 || len(opts) > 2 {\n\t\t\t\t\treturn ctx, fmt.Errorf(\"expected 2 options, got %v: %v\", len(opts), opts)\n\t\t\t\t}\n\n\t\t\t\theapProfileSamplingFrequencySeconds, err := strconv.Atoi(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\theapProfileMaxTimeBetweenDumpsSeconds, err := strconv.Atoi(opts[1])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tsamplingFrequencySeconds = heapProfileSamplingFrequencySeconds\n\t\t\t\tmaxTimeBetweenDumpsSeconds = heapProfileMaxTimeBetweenDumpsSeconds\n\n\t\t\t\treturn ctx, nil\n\t\t\t},\n\t\t}\n\t}\n\thooks.RegisterHook(\"beam:go:hook:diagnostics:heapDump\", hf)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/harness/diagnostics_hook.go#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"Workers launched with incomplete option strings, trailing commas, or format changes between Beam versions that altered the expected option count.","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."],"exampleFix":"// before\n--diagnostics_sampling_frequency=\"30\"\n// after\n--diagnostics_sampling_frequency=\"30,30\"","handlingStrategy":"validation","validationCode":"opts := strings.Split(diagOpt, \",\")\nif len(opts) != 2 { return fmt.Errorf(\"diagnostics hook needs exactly 2 options, got %d\", len(opts)) }\nfor _, o := range opts { if _, err := strconv.Atoi(strings.TrimSpace(o)); err != nil { return err } }","typeGuard":null,"tryCatchPattern":"if err := hook.Init(ctx); err != nil {\n\tlog.Fatalf(\"diagnostics hook option error: %v\", err)\n}","preventionTips":["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."],"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"}