{"record":{"id":"7877aae3acb95ce8","repo":"apache/beam","slug":"error-reading-label-flag-as-json","errorCode":null,"errorMessage":"error reading --label flag as JSON","messagePattern":"error reading --label flag as JSON","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/dataflow/dataflow.go","lineNumber":287,"sourceCode":"func getJobOptions(ctx context.Context, streaming bool) (*dataflowlib.JobOptions, error) {\n\tproject := gcpopts.GetProjectFromFlagOrEnvironment(ctx)\n\tif project == \"\" {\n\t\treturn nil, errors.New(\"no Google Cloud project specified. Use --project=<project>\")\n\t}\n\tregion := gcpopts.GetRegion(ctx)\n\tif region == \"\" {\n\t\treturn nil, errors.New(\"no Google Cloud region specified. Use --region=<region>. See https://cloud.google.com/dataflow/docs/concepts/regional-endpoints\")\n\t}\n\tif *stagingLocation == \"\" {\n\t\treturn nil, errors.New(\"no GCS staging location specified. Use --staging_location=gs://<bucket>/<path>\")\n\t}\n\n\tcheckSoftDeletePolicyEnabled(ctx, *stagingLocation, \"staging_location\")\n\n\tvar jobLabels map[string]string\n\tif *labels != \"\" {\n\t\tif err := json.Unmarshal([]byte(*labels), &jobLabels); err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"error reading --label flag as JSON\")\n\t\t}\n\t}\n\n\tif *cpuProfiling != \"\" {\n\t\tperf.EnableProfCaptureHook(\"gcs_profile_writer\", *cpuProfiling)\n\t}\n\n\tif *autoscalingAlgorithm != \"\" {\n\t\tif *autoscalingAlgorithm != \"NONE\" && *autoscalingAlgorithm != \"THROUGHPUT_BASED\" {\n\t\t\treturn nil, errors.New(\"invalid autoscaling algorithm. Use --autoscaling_algorithm=(NONE|THROUGHPUT_BASED)\")\n\t\t}\n\t}\n\n\tif *flexRSGoal != \"\" {\n\t\tswitch *flexRSGoal {\n\t\tcase \"FLEXRS_UNSPECIFIED\", \"FLEXRS_SPEED_OPTIMIZED\", \"FLEXRS_COST_OPTIMIZED\":\n\t\t\t// valid values\n\t\tdefault:","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/dataflow/dataflow.go#L269-L305","documentation":"getJobOptions in the Dataflow runner parses the --label command-line flag as a JSON object mapping label keys to values. If json.Unmarshal of the flag's contents fails, the error is wrapped with this message and returned, aborting job option construction. Labels must be valid JSON of the form {\"key\":\"value\"}.","triggerScenarios":"Launching a Dataflow pipeline with a non-empty --label flag whose value is not valid JSON (e.g. single quotes, unquoted keys, trailing commas, or a plain key=value string).","commonSituations":"Shell quoting issues where single-quoted JSON is passed but interpreted incorrectly, users passing key=value pairs instead of a JSON object, copying labels from documentation with markdown quotes, or CI variables containing escaped quotes.","solutions":["Pass the --label flag as a valid JSON object, e.g. --label='{\"env\":\"prod\",\"team\":\"data\"}'","Validate the JSON locally with `echo '<value>' | jq .` before launching","Check shell quoting: wrap the JSON in single quotes so double quotes survive","If no labels are needed, omit the flag entirely (empty string is skipped)"],"exampleFix":"// before\n--label=env=prod,team=data\n// after\n--label='{\"env\":\"prod\",\"team\":\"data\"}'","handlingStrategy":"validation","validationCode":"if labels != \"\" {\n    var m map[string]string\n    if err := json.Unmarshal([]byte(labels), &m); err != nil {\n        return fmt.Errorf(\"--label flag is not valid JSON: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n    if strings.Contains(err.Error(), \"--label flag\") {\n        log.Fatalf(\"fix --label JSON: %v\", err)\n    }\n}","preventionTips":["Always pass --label as a double-quoted JSON object in single-quoted shell args","Validate flag JSON with jq before launching","Never pass key=value pairs where JSON objects are expected","Keep label definitions in config files parsed once and validated at startup"],"tags":["go","dataflow","cli-flag","json"],"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-14T21:17:11.552Z"}