apache/beam · error
error parsing JSON: of request
Error message
error parsing JSON: %s of request: %w
What it means
Error built in jobCancelHandler.ServeHTTP when json.Unmarshal of the POST body into cancelJobRequest fails — malformed JSON, wrong types, or trailing garbage. The raw body is echoed in the message to aid debugging, and the client receives HTTP 400.
Solutions
- Send a valid JSON object with a 'job_id' string field, e.g. {"job_id": "..."}
- Remove trailing commas or extra data after the JSON object
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:398 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/674a21f8dd011774.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:398
func (h *jobCancelHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var cancelRequest *cancelJobRequest
if r.Method != http.MethodPost {
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read request body: %w", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if len(body) == 0 {
http.Error(w, "empty request body", http.StatusBadRequest)
return
}
if err := json.Unmarshal(body, &cancelRequest); err != nil {
err = fmt.Errorf("error parsing JSON: %s of request: %w", body, err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Forward JobId from POST body avoids direct json Unmarshall on composite types containing protobuf message types.
resp, err := h.Jobcli.Cancel(r.Context(), &jobpb.CancelJobRequest{
JobId: cancelRequest.JobID,
})
if err != nil {
statusCode := status.Code(err)
httpCode := http.StatusInternalServerError
if c, ok := grpcToHttpCodes[statusCode]; ok {
httpCode = c
}
err = fmt.Errorf("error Cancel(%+v) = %w", cancelRequest, err)
http.Error(w, err.Error(), httpCode)
}
View on GitHub (pinned to 12126d8942)