{"record":{"id":"9836c5b19e8f7dd0","repo":"apache/beam","slug":"invalid-dictionary-call","errorCode":null,"errorMessage":"Invalid dictionary call","messagePattern":"Invalid dictionary call","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/go/cmd/specialize/main.go","lineNumber":262,"sourceCode":"\tvar ret []int\n\tfor k := 0; k < i; k++ {\n\t\tret = append(ret, k)\n\t}\n\treturn ret\n}\n\nfunc add(i int, j int) int {\n\treturn i + j\n}\n\nfunc mult(i int, j int) int {\n\treturn i * j\n}\n\nfunc dict(values ...any) map[string]any {\n\tdict := make(map[string]any, len(values)/2)\n\tif len(values)%2 != 0 {\n\t\tpanic(\"Invalid dictionary call\")\n\t}\n\tfor i := 0; i < len(values); i += 2 {\n\t\tdict[values[i].(string)] = values[i+1]\n\t}\n\n\treturn dict\n}\n\nfunc list(values ...string) []string {\n\treturn values\n}\n\nfunc genericTypingRepresentation(in int, out int, includeType bool) string {\n\tseenElements := false\n\ttyping := \"\"\n\tif in > 0 {\n\t\ttyping += fmt.Sprintf(\"[I%v\", 0)\n\t\tfor i := 1; i < in; i++ {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/cmd/specialize/main.go#L244-L280","documentation":"The specialize tool's dict helper builds a map[string]any from alternating key/value arguments. If an odd number of arguments is passed — meaning some key has no value — it panics with 'Invalid dictionary call'.","triggerScenarios":"Calling dict() inside the specialize tool's template data construction with an odd number of arguments, e.g. dict(\"key1\", v1, \"key2\") with a missing value.","commonSituations":"Editing the specialize tool's generated-code parameters and dropping one of a key/value pair; adding a template variable without its value.","solutions":["Ensure dict() is only ever called with an even number of arguments (key, value pairs)","Check each dict(...) call site in main.go and count its arguments","Add a compile-time constant or struct for template params instead of variadic pairs to avoid recurrence"],"exampleFix":"// before\ndict(\"namespace\", ns, \"params\")\n// after\ndict(\"namespace\", ns, \"params\", params)","handlingStrategy":"validation","validationCode":"if len(args)%2 != 0 {\n\treturn errors.New(\"dict requires key/value pairs\")\n}","typeGuard":null,"tryCatchPattern":"// in the specialize tool\nif len(values)%2 != 0 {\n\treturn fmt.Errorf(\"dict called with odd arg count at %s\", callerSite)\n}","preventionTips":["Count key/value pairs before calling dict","Prefer explicit map literals or structs over variadic key/value helpers"],"tags":["go","apache-beam","panic","tooling"],"backgroundTag":"invalid-argument-format","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"}