{"record":{"id":"46929a05bbba6a1a","repo":"googleapis/mcp-toolbox","slug":"failed-to-unmarshal-context-from-yaml-w","errorCode":null,"errorMessage":"failed to unmarshal context from yaml: %w","messagePattern":"failed to unmarshal context from yaml: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudgda/cloudgda.go","lineNumber":77,"sourceCode":"\t}\n\treturn actual, nil\n}\n\ntype compatibleSource interface {\n\tGetProjectID() string\n\tUseClientAuthorization() bool\n\tRunQuery(context.Context, string, *geminidataanalyticspb.QueryDataRequest) (*geminidataanalyticspb.QueryDataResponse, error)\n}\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 {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudgda/cloudgda.go#L59-L95","documentation":"QueryDataContext.UnmarshalYAML first parses the YAML bytes into a generic map before converting to the proto message. If the YAML itself is malformed (bad indentation, tabs, invalid syntax), the yaml.Unmarshal step fails and this wrapped error is returned. It means the `context` block in a cloud-gda tool config could not even be parsed as YAML.","triggerScenarios":"A QueryDataContext node in YAML (e.g. a cloud-gda tool's context field) containing tabs for indentation, unbalanced quotes/brackets, or other invalid YAML passed through yaml.Unmarshal(b, &raw).","commonSituations":"Hand-editing the context block and breaking indentation; pasting JSON with duplicate keys or trailing commas then editing; editors inserting tabs instead of spaces.","solutions":["Validate the YAML snippet with a linter (yamllint or an editor) and fix the syntax error named in the wrapped message.","Replace tab characters with spaces in the context block.","Quote strings containing special characters (:, #, {, }) properly.","Compare against a working cloud-gda example config in docs/en."],"exampleFix":"// before (invalid)\ncontext:\n\ttableReferences:\n\t- tableName: orders\n// after\ncontext:\n  tableReferences:\n    - tableName: orders","handlingStrategy":"validation","validationCode":"// Pre-validate the context YAML before loading the config\nimport \"gopkg.in/yaml.v3\"\nfunc validateContextYAML(s string) error {\n    var m map[string]any\n    if err := yaml.Unmarshal([]byte(s), &m); err != nil {\n        return fmt.Errorf(\"invalid context YAML: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"var qd QueryDataContext\nif err := yaml.Unmarshal(rawBytes, &qd); err != nil {\n    if strings.Contains(err.Error(), \"failed to unmarshal context from yaml\") {\n        return fmt.Errorf(\"fix the `context:` block syntax (check tabs/indentation): %w\", err)\n    }\n    return err\n}","preventionTips":["Use spaces, never tabs, in YAML context blocks.","Run yamllint on the toolbox config before deploying.","Keep context snippets in sync with current cloud-gda docs."],"tags":["yaml","cloudgda","unmarshal","config"],"backgroundTag":"yaml-parse-error","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"}