{"record":{"id":"c64551e3d6824ffc","repo":"googleapis/mcp-toolbox","slug":"failed-to-unmarshal-operation-bytes-w","errorCode":null,"errorMessage":"failed to unmarshal operation bytes: %w","messagePattern":"failed to unmarshal operation bytes: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/alloydbadmin/alloydbadmin.go","lineNumber":371,"sourceCode":"\n\t\t\tvar opBytes []byte\n\t\t\topBytes, err = op.MarshalJSON()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not marshal operation: %w\", err)\n\t\t\t}\n\n\t\t\tif op.Response != nil {\n\t\t\t\tvar responseData map[string]any\n\t\t\t\tif err := json.Unmarshal(op.Response, &responseData); err == nil && responseData != nil {\n\t\t\t\t\tif msg, ok := generateAlloyDBConnectionMessage(responseData, connectionMessageTemplate); ok {\n\t\t\t\t\t\treturn msg, nil\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar result any\n\t\t\tif err := json.Unmarshal(opBytes, &result); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to unmarshal operation bytes: %w\", err)\n\t\t\t}\n\t\t\treturn result, nil\n\t\t}\n\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"Operation not complete, retrying in %v\\n\", delay))\n\t}\n\treturn nil, nil\n}\n\nfunc generateAlloyDBConnectionMessage(responseData map[string]any, connectionMessageTemplate string) (string, bool) {\n\tresourceName, ok := responseData[\"name\"].(string)\n\tif !ok {\n\t\treturn \"\", false\n\t}\n\n\tparts := strings.Split(resourceName, \"/\")\n\tvar project, region, cluster, instance string\n\n\t// Expected format: projects/{project}/locations/{location}/clusters/{cluster}","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/alloydbadmin/alloydbadmin.go#L353-L389","documentation":"After successfully marshaling the completed operation to JSON bytes, GetOperations unmarshals those bytes into a generic any so the result can be returned as structured data. This error means the round-trip failed — the JSON bytes the tool itself just produced could not be parsed, which indicates a deep inconsistency (corrupt bytes, encoding issue) in the marshaled payload.","triggerScenarios":"Calling GetOperations on a DONE operation where json.Unmarshal(opBytes, &result) fails — practically only when MarshalJSON produced bytes that are not valid JSON (e.g. embedded invalid UTF-8 or non-standard JSON from the operation's MarshalJSON implementation).","commonSituations":"Operation payloads containing invalid UTF-8 strings or exotic values that marshal to non-standard JSON; SDK version bugs in the longrunning operation's MarshalJSON.","solutions":["Retry the call; inspect the wrapped error for 'invalid character' or 'invalid UTF-8' clues.","Log/dump opBytes (or a safe prefix) to see what failed to parse.","Check the operation payload via `gcloud alloydb operations describe <op>` for non-UTF-8 or unusual metadata.","Upgrade the AlloyDB Admin Go SDK to the latest version.","If reproducible, file a bug against the SDK's operation MarshalJSON."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure the operation payload is sane via a direct API read before round-tripping\nop, err := adminClient.GetOperation(ctx, &adminpb.GetOperationRequest{Name: opName})\nif err != nil { return err }\nif _, err := json.Marshal(op); err != nil { return fmt.Errorf(\"operation payload not serializable: %w\", err) }","typeGuard":null,"tryCatchPattern":"result, err := toolbox.GetOperations(ctx, opName)\nvar opErr *errLookup\nif errors.As(err, &opErr) && strings.Contains(err.Error(), \"failed to unmarshal operation bytes\") {\n    // fall back to describing the operation directly via the Admin API\n}","preventionTips":["Use latest SDK versions where MarshalJSON bugs are fixed","Log opBytes safely (truncated) on failure","Cross-check operation payloads with `gcloud alloydb operations describe`","File SDK bugs when invalid-JSON marshaling is reproducible"],"tags":["go","serialization","json","alloydb"],"backgroundTag":"json-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"}