{"record":{"id":"25a7592b40b4da19","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-context-map-w","errorCode":null,"errorMessage":"failed to marshal context map: %w","messagePattern":"failed to marshal context map: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/tools/cloudgda/cloudgda.go","lineNumber":81,"sourceCode":"type 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 {\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}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudgda/cloudgda.go#L63-L99","documentation":"After parsing YAML into map[string]any, UnmarshalYAML re-marshals it to JSON so protojson can populate the QueryDataContext proto. A failure here means the generic map cannot be serialized to JSON — extremely rare, since yaml.Unmarshal into map[string]any only yields JSON-serializable values (maps, slices, scalars).","triggerScenarios":"json.Marshal(raw) returning an error after yaml parsing succeeded; practically only via unusual custom YAML decoders or corrupted intermediate state.","commonSituations":"Almost never hit in real configs; would indicate a library-level or decoder-hook (e.g. custom yaml funcmap) issue rather than user error.","solutions":["Inspect the wrapped error and the raw map values for non-JSON-serializable types from custom yaml.Unmarshaler hooks.","Update the MCP Toolbox version in case of a library bug.","File an issue with the exact YAML input if reproducible."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := yaml.Unmarshal(b, &qd); err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal context map\") {\n        // library-level failure; report with the raw YAML for an upstream issue\n        return fmt.Errorf(\"context map -> JSON failed; report input: %w\", err)\n    }\n    return err\n}","preventionTips":["Avoid custom yaml.Unmarshaler hooks that inject non-JSON types.","Keep the toolbox binary up to date.","Retain the offending YAML input for bug reports."],"tags":["yaml","cloudgda","json","marshal"],"backgroundTag":"json-marshaling-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"}