{"record":{"id":"f599400c4a1c926c","repo":"googleapis/mcp-toolbox","slug":"failed-to-unmarshal-context-to-proto-w","errorCode":null,"errorMessage":"failed to unmarshal context to proto: %w","messagePattern":"failed to unmarshal context to proto: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudgda/cloudgda.go","lineNumber":85,"sourceCode":"}\n\n// QueryDataContext wraps geminidataanalyticspb.QueryDataContext to support YAML decoding via protojson.\ntype QueryDataContext struct {\n\t*geminidataanalyticspb.QueryDataContext\n}\n\nfunc (q *QueryDataContext) 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 context from yaml: %w\", err)\n\t}\n\tjsonBytes, err := json.Marshal(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal context map: %w\", err)\n\t}\n\tq.QueryDataContext = &geminidataanalyticspb.QueryDataContext{}\n\tif err := protojson.Unmarshal(jsonBytes, q.QueryDataContext); err != nil {\n\t\treturn fmt.Errorf(\"failed to unmarshal context to proto: %w\", err)\n\t}\n\treturn nil\n}\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}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudgda/cloudgda.go#L67-L103","documentation":"The final step of QueryDataContext.UnmarshalYAML feeds the JSON bytes to protojson.Unmarshal to build geminidataanalyticspb.QueryDataContext. protojson rejects fields that don't match the proto schema (unknown fields, wrong types, badly formatted values), so schema-mismatched context YAML produces this wrapped error.","triggerScenarios":"A context block whose keys don't match QueryDataContext proto fields (e.g. misspelled `tableReferences`, unexpected nested field), wrong value types (string where a message/list is expected), or invalid nested structures.","commonSituations":"Following outdated documentation for the context schema; guessing field names instead of checking the proto definition; providing a scalar where `tableReferences` expects a repeated message with `tableName`.","solutions":["Check the wrapped protojson error for the offending field and correct the key name/type in the YAML.","Compare your context block with the QueryDataContext proto fields (tableReferences, etc.) and the official cloud-gda docs.","Ensure tableReferences entries are objects like `- tableName: my_table`.","Remove unknown fields if protojson strict mode rejects them."],"exampleFix":"// before\ncontext:\n  tableRefs:\n    - name: orders\n// after\ncontext:\n  tableReferences:\n    - tableName: orders","handlingStrategy":"validation","validationCode":"// Validate context keys against the proto schema before unmarshaling\nfunc checkContextKeys(m map[string]any) error {\n    allowed := map[string]bool{\"tableReferences\": true /*, other QueryDataContext fields */}\n    for k := range m {\n        if !allowed[k] {\n            return fmt.Errorf(\"unknown context field %q\", k)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := yaml.Unmarshal(b, &qd); err != nil {\n    if strings.Contains(err.Error(), \"failed to unmarshal context to proto\") {\n        return fmt.Errorf(\"context fields must match QueryDataContext proto (e.g. tableReferences[].tableName): %w\", err)\n    }\n    return err\n}","preventionTips":["Copy context structure from the official cloud-gda tool docs/examples.","Spell proto field names exactly (camelCase: tableReferences, tableName).","Use object entries `- tableName: x` under tableReferences, not plain strings.","Test config loading locally with `go run . --tools-file` before deploying."],"tags":["cloudgda","protojson","unmarshal","config"],"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"}