{"record":{"id":"05319a6a167587bb","repo":"googleapis/mcp-toolbox","slug":"error-marshaling-dynamic-fields-w","errorCode":null,"errorMessage":"error marshaling dynamic_fields: %w","messagePattern":"error marshaling dynamic_fields: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/looker/lookercommon/lookercommon.go","lineNumber":364,"sourceCode":"\t\t}\n\t\ttz = tzname\n\t}\n\n\tvar filterExpressionPtr *string\n\tif val, ok := paramsMap[\"filter_expression\"]; ok && val != nil {\n\t\tif strVal, ok := val.(string); ok {\n\t\t\tfilterExpressionPtr = &strVal\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"'filter_expression' must be a string, got %T\", val)\n\t\t}\n\t}\n\n\tvar dynamicFieldsPtr *string\n\tif val, ok := paramsMap[\"dynamic_fields\"]; ok && val != nil {\n\t\tif sliceVal, ok := val.([]any); ok && len(sliceVal) > 0 {\n\t\t\tjsonBytes, err := json.Marshal(sliceVal)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error marshaling dynamic_fields: %w\", err)\n\t\t\t}\n\t\t\tjsonStr := string(jsonBytes)\n\t\t\tdynamicFieldsPtr = &jsonStr\n\t\t}\n\t}\n\n\twq := v4.WriteQuery{\n\t\tModel:            paramsMap[\"model\"].(string),\n\t\tView:             paramsMap[\"explore\"].(string),\n\t\tFields:           &fields,\n\t\tPivots:           &pivots,\n\t\tFilters:          &filters,\n\t\tSorts:            &sorts,\n\t\tQueryTimezone:    &tz,\n\t\tLimit:            &limit,\n\t\tFilterExpression: filterExpressionPtr,\n\t\tDynamicFields:    dynamicFieldsPtr,\n\t}","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/looker/lookercommon/lookercommon.go#L346-L382","documentation":"ProcessQueryArgs accepts 'dynamic_fields' as a []any and serializes it to a JSON string for the Looker API. If json.Marshal fails on the slice (e.g. it contains values that cannot be marshaled such as channels or cyclic structures in Go callers), this wrapped error is returned.","triggerScenarios":"Passing a dynamic_fields slice containing unmarshalable values; in practice from Go callers embedding unsupported types into the []any; JSON-safe clients rarely trigger this.","commonSituations":"Programmatic Go callers building the params map with non-JSON types; corrupted callback/func values injected into the slice; extremely rare when parameters come from JSON decoding since decoded []any is always JSON-safe.","solutions":["Ensure dynamic_fields is a JSON-serializable array of objects, e.g. [{\"name\":\"total\",\"expression\":\"${sum}\"}]","Inspect the wrapped %w error for the specific unmarshalable value","Rebuild the slice using only maps, slices, strings, numbers, and bools","If coming from JSON input, this error is near-impossible — verify you are not pre-processing the slice into non-JSON types"],"exampleFix":"// before\nparamsMap[\"dynamic_fields\"] = []any{func() {}}\n// after\nparamsMap[\"dynamic_fields\"] = []any{map[string]any{\"name\": \"total\", \"expression\": \"sum(x)\"}}","handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(dynamicFields); err != nil {\n\t// fix the slice before calling the tool\n}","typeGuard":"func jsonSafe(v []any) bool { return json.NewDecoder(strings.NewReader(stringify(v))) == nil || marshalable(v) }\nfunc marshalable(v any) bool { return json.Marshal(v) == nil }","tryCatchPattern":"df, err := json.Marshal(params[\"dynamic_fields\"])\nif err != nil {\n\treturn fmt.Errorf(\"pre-check dynamic_fields marshal failed: %w\", err)\n}","preventionTips":["Only populate dynamic_fields with JSON-decoded values","Pre-marshal in tests to catch unsupported types early"],"tags":["looker","json","serialization"],"backgroundTag":"json-serialization-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"}