{"record":{"id":"40050c20efa2198a","repo":"googleapis/mcp-toolbox","slug":"failed-to-unmarshal-generation-options-to-proto","errorCode":null,"errorMessage":"failed to unmarshal generation options to proto: %w","messagePattern":"failed to unmarshal generation options to proto: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudgda/cloudgda.go","lineNumber":106,"sourceCode":"}\n\n// GenerationOptions wraps geminidataanalyticspb.GenerationOptions to support YAML decoding via protojson.\ntype GenerationOptions struct {\n\t*geminidataanalyticspb.GenerationOptions\n}\n\nfunc (g *GenerationOptions) UnmarshalYAML(b []byte) error {\n\tvar raw map[string]any\n\tif err := yaml.Unmarshal(b, &raw); err != nil {\n\t\treturn fmt.Errorf(\"failed to unmarshal generation options from yaml: %w\", err)\n\t}\n\tjsonBytes, err := json.Marshal(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal generation options map: %w\", err)\n\t}\n\tg.GenerationOptions = &geminidataanalyticspb.GenerationOptions{}\n\tif err := protojson.Unmarshal(jsonBytes, g.GenerationOptions); err != nil {\n\t\treturn fmt.Errorf(\"failed to unmarshal generation options to proto: %w\", err)\n\t}\n\treturn nil\n}\n\ntype Config struct {\n\ttools.ConfigBase  `yaml:\",inline\"`\n\tType              string                 `yaml:\"type\" validate:\"required\"`\n\tSource            string                 `yaml:\"source\" validate:\"required\"`\n\tLocation          string                 `yaml:\"location\" validate:\"required\"`\n\tContext           *QueryDataContext      `yaml:\"context\" validate:\"required\"`\n\tGenerationOptions *GenerationOptions     `yaml:\"generationOptions,omitempty\"`\n\tAnnotations       *tools.ToolAnnotations `yaml:\"annotations,omitempty\"`\n}\n\n// validate interface\nvar _ tools.ToolConfig = Config{}\n\nfunc (cfg Config) ToolConfigType() string {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudgda/cloudgda.go#L88-L124","documentation":"The JSON bytes produced from the YAML map are unmarshaled into the protobuf message geminidataanalyticspb.GenerationOptions using protojson. This error fires when keys or value shapes do not match the proto schema (protojson validates field names and types strictly, unlike plain JSON decoding).","triggerScenarios":"Using unknown field names in generationOptions (protojson rejects unknown fields by default), wrong value types for known fields (e.g. a string where an enum name or bool is expected), or mapping under a field that is not a message.","commonSituations":"Typos in proto field names (e.g. queryMod instead of queryMode); using camelCase vs snake_case inconsistently; copying options from a different API version whose schema changed; nesting a map where proto expects a scalar.","solutions":["Check each key in generationOptions against the GenerationOptions proto message in google.golang.org/api/geminidataanalytics/v1alpha (or matching version) and fix names/types","Use exact proto field names (the JSON names, typically lowerCamelCase) for all keys","Remove unknown keys; protojson with default options rejects them","Pin a matching google-api-go-client version so the proto schema matches your intended fields"],"exampleFix":"// before (unknown field 'queryMod', wrong enum type)\ngenerationOptions:\n  queryMod: \"AUTO\"\n// after\ngenerationOptions:\n  queryMode: AUTO","handlingStrategy":"validation","validationCode":"import (\"encoding/json\"; \"google.golang.org/protobuf/encoding/protojson\")\nfunc validProtoShape(b []byte, msg proto.Message) error {\n\tvar m map[string]any\n\tif err := yaml.Unmarshal(b, &m); err != nil { return err }\n\tjb, _ := json.Marshal(m)\n\treturn protojson.Unmarshal(jb, msg)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cross-check every generationOptions key against the GenerationOptions proto definition","Use exact proto JSON field names (lowerCamelCase)","Pin the google-api-go-client version matching your field names"],"tags":["protojson","yaml","cloud-gemini-data-analytics"],"backgroundTag":"proto-unmarshal-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}