googleapis/mcp-toolbox · error
failed to unmarshal job JSON: %w
Error message
failed to unmarshal job JSON: %w
What it means
GetJob unmarshals the protojson-produced bytes into map[string]any. This error means json.Unmarshal failed on bytes that protojson just produced — practically indicates the JSON bytes are invalid, which points to a corrupted marshal step or memory/exotic edge case rather than user input.
Source
Thrown at internal/sources/dataproc/dataproc.go:410
req := &dataprocpb.GetJobRequest{
ProjectId: s.Project,
Region: s.Region,
JobId: jobId,
}
jobPb, err := client.GetJob(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to get job: %w", err)
}
jsonBytes, err := protojson.Marshal(jobPb)
if err != nil {
return nil, fmt.Errorf("failed to marshal job to JSON: %w", err)
}
var result map[string]any
if err := json.Unmarshal(jsonBytes, &result); err != nil {
return nil, fmt.Errorf("failed to unmarshal job JSON: %w", err)
}
consoleUrl := JobConsoleURLFromProto(jobPb, s.Region)
logsUrl, err := JobLogsURLFromProto(jobPb, s.Region)
if err != nil {
return nil, fmt.Errorf("error generating logs url: %v", err)
}
wrappedResult := map[string]any{
"consoleUrl": consoleUrl,
"logsUrl": logsUrl,
"job": result,
}
return wrappedResult, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Log jsonBytes on failure to inspect what protojson produced
- Verify the standard encoding/json package is in use (no shadowed imports/build tags)
- Rebuild the project cleanly (go clean && go build) to rule out stale artifacts
Defensive patterns
Strategy: retry
Try / catch
job, err := svc.GetJob(ctx, jobId)
if err != nil && strings.Contains(err.Error(), "unmarshal job JSON") {
// rebuild cleanly and retry; log jsonBytes if reproducible
} Prevention
- Avoid shadowing the encoding/json import
- Rebuild with go clean after unusual toolchain or vendoring changes
- Report persistent occurrences upstream
When it happens
Trigger: json.Unmarshal(jsonBytes, &result) failing after protojson.Marshal succeeded — an internal inconsistency, essentially unreachable in normal operation.
Common situations: Effectively only seen with custom builds, instrumented JSON libraries, or vendoring anomalies.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- operation finished with error but could not marshal error ob
- failed to unmarshal cluster JSON: %w
- failed to marshal job to JSON: %w
- failed to marshal result: %w
- failed to unmarshal operation bytes: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/97f187c1fa1003fc.
Report an issue: GitHub.