{"record":{"id":"b5ceee072c7a15d6","repo":"googleapis/mcp-toolbox","slug":"failed-to-unmarshal-operation-json-to-map-w","errorCode":null,"errorMessage":"failed to unmarshal operation JSON to map: %w","messagePattern":"failed to unmarshal operation JSON to map: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dataplex/dataplex.go","lineNumber":927,"sourceCode":"\t\treturn nil, fmt.Errorf(\"invalid operation name format: %q (expected projects/*/locations/*/operations/*)\", opName)\n\t}\n\n\treq := &longrunningpb.GetOperationRequest{\n\t\tName: opName,\n\t}\n\top, err := s.DataScanClient.LROClient.GetOperation(ctx, req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tbytes, err := protojson.Marshal(op)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal operation to JSON: %w\", err)\n\t}\n\n\tvar opData map[string]any\n\tif err := json.Unmarshal(bytes, &opData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal operation JSON to map: %w\", err)\n\t}\n\n\treturn opData, nil\n}\n\nfunc (s *Source) GetJobStatus(ctx context.Context, location, scanID, jobID string) (*dataplexpb.DataScanJob, error) {\n\t// If jobID is provided, fetch that specific job directly!\n\tif jobID != \"\" {\n\t\tname := fmt.Sprintf(\"projects/%s/locations/%s/dataScans/%s/jobs/%s\", s.ProjectID(), location, scanID, jobID)\n\t\treq := &dataplexpb.GetDataScanJobRequest{\n\t\t\tName: name,\n\t\t}\n\t\treturn s.DataScanClient.GetDataScanJob(ctx, req)\n\t}\n\n\t// Fallback to listing and returning the latest job (PageSize: 1)\n\tparent := fmt.Sprintf(\"projects/%s/locations/%s/dataScans/%s\", s.ProjectID(), location, scanID)\n\treq := &dataplexpb.ListDataScanJobsRequest{","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dataplex/dataplex.go#L909-L945","documentation":"After GetOperation successfully marshals the operation with protojson, it decodes the JSON bytes into a map[string]any for the caller. If the JSON produced cannot be unmarshaled into a map (corrupt or non-object payload), this wrapped error is returned. Practically unreachable with valid protojson output, but it hardens the conversion path.","triggerScenarios":"Calling GetOperation when the intermediate JSON bytes from protojson.Marshal are not a valid JSON object (only possible with corrupted output or replaced marshaler behavior).","commonSituations":"Custom/patched protojson behavior; intermediary mutation of bytes; extremely rare in production — mostly seen in mocked or instrumented clients.","solutions":["Inspect the wrapped error from json.Unmarshal for the exact cause","Re-run with a stock protojson.Marshal to confirm output is a JSON object","Ensure no middleware rewrites the marshaled bytes","Update the dataplex client/proto dependencies if a known bug applies"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if len(bytes) == 0 || bytes[0] != '{' { return errors.New(\"operation payload is not a JSON object\") }","typeGuard":null,"tryCatchPattern":"opData, err := src.GetOperation(ctx, name)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unmarshal operation JSON\") {\n\t\t// fall back to raw operation proto inspection\n\t}\n\treturn err\n}","preventionTips":["Use stock protojson without intermediaries","Avoid post-processing the marshaled bytes","Report persistent failures with the wrapped cause to SDK maintainers"],"tags":["dataplex","json","unmarshal","gcp"],"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"}