{"record":{"id":"8d1c2706ffc1062c","repo":"apache/beam","slug":"could-not-unmarshal-sourceconfig-v","errorCode":null,"errorMessage":"Could not unmarshal SourceConfig: %v","messagePattern":"Could not unmarshal SourceConfig: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/synthetic/source.go","lineNumber":294,"sourceCode":"\n// BuildFromJSON constructs the SourceConfig by populating it with the parsed\n// JSON. Panics if there is an error in the syntax of the JSON or if the input\n// contains unknown object keys.\n//\n// An example of valid JSON object:\n//\n//\t{\n//\t\t \"num_records\": 5,\n//\t\t \"key_size\": 5,\n//\t\t \"value_size\": 5,\n//\t\t \"num_hot_keys\": 5,\n//\t}\nfunc (b *SourceConfigBuilder) BuildFromJSON(jsonData []byte) SourceConfig {\n\tdecoder := json.NewDecoder(bytes.NewReader(jsonData))\n\tdecoder.DisallowUnknownFields()\n\n\tif err := decoder.Decode(&b.cfg); err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not unmarshal SourceConfig: %v\", err))\n\t}\n\treturn b.cfg\n}\n\n// SourceConfig is a struct containing all the configuration options for a\n// synthetic source. It should be created via a SourceConfigBuilder, not by\n// directly initializing it (the fields are public to allow encoding).\ntype SourceConfig struct {\n\tNumElements    int64   `json:\"num_records\" beam:\"num_records\"`\n\tInitialSplits  int64   `json:\"initial_splits\" beam:\"initial_splits\"`\n\tKeySize        int64   `json:\"key_size\" beam:\"key_size\"`\n\tValueSize      int64   `json:\"value_size\" beam:\"value_size\"`\n\tNumHotKeys     int64   `json:\"num_hot_keys\" beam:\"num_hot_keys\"`\n\tHotKeyFraction float64 `json:\"hot_key_fraction\" beam:\"hot_key_fraction\"`\n}\n","sourceCodeStart":276,"sourceCodeEnd":310,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/synthetic/source.go#L276-L310","documentation":"SourceConfigBuilder.BuildFromJSON() panics when the provided JSON cannot be decoded into SourceConfig. The decoder uses DisallowUnknownFields(), so both malformed JSON and any unrecognized field name fail decoding. This is an early-validation guard so bad pipeline configs abort at graph construction instead of at runtime.","triggerScenarios":"Passing JSON with a typo'd or unknown field to BuildFromJSON (e.g. \"numHotkeys\" vs \"NumHotKeys\"), malformed JSON syntax, or a value whose type does not match the struct field (string where a number is expected).","commonSituations":"Hand-authoring synthetic source options in pipeline templates or YAML-embedded JSON; version drift where a newer/older Beam expects fields the JSON doesn't match; case-sensitivity mistakes in field names.","solutions":["Validate the JSON with a plain json.Unmarshal into SourceConfig first and inspect the error message for the offending field.","Remove or rename unknown fields so they exactly match SourceConfig field names (case-sensitive, no snake_case).","Check value types: durations must be strings like '10ms', counts must be numbers.","Verify the Beam SDK version supports the fields you are passing."],"exampleFix":"// before\n{\"NumHotKeys\": \"10\"}\n// after\n{\"NumHotKeys\": 10}","handlingStrategy":"validation","validationCode":"var cfg synthetic.SourceConfig\nif err := json.Unmarshal(jsonData, &cfg); err != nil {\n    return fmt.Errorf(\"invalid SourceConfig JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate JSON from the Go struct (marshal a template) so field names always match.","Watch out for DisallowUnknownFields: any extra field fails.","Validate JSON with a lint/schema check in CI before deploying pipelines."],"tags":["go","apache-beam","json","unmarshal","panic"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}