{"record":{"id":"54ce4c703e1ec4bc","repo":"hashicorp/nomad","slug":"failed-to-encode-task-stats-v","errorCode":null,"errorMessage":"failed to encode task stats: %v","messagePattern":"failed to encode task stats: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/drivers/server.go","lineNumber":283,"sourceCode":"\n\tch, err := b.impl.TaskStats(srv.Context(), req.TaskId, interval)\n\tif err != nil {\n\t\tif rec, ok := err.(structs.Recoverable); ok {\n\t\t\tst := status.New(codes.FailedPrecondition, rec.Error())\n\t\t\tst, err := st.WithDetails(&sproto.RecoverableError{Recoverable: rec.IsRecoverable()})\n\t\t\tif err != nil {\n\t\t\t\t// If this error, it will always error\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t\treturn st.Err()\n\t\t}\n\t\treturn err\n\t}\n\n\tfor stats := range ch {\n\t\tpb, err := TaskStatsToProto(stats)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to encode task stats: %v\", err)\n\t\t}\n\n\t\tif err = srv.Send(&proto.TaskStatsResponse{Stats: pb}); err == io.EOF {\n\t\t\tbreak\n\t\t} else if err != nil {\n\t\t\treturn err\n\t\t}\n\n\t}\n\n\treturn nil\n}\n\nfunc (b *driverPluginServer) ExecTask(ctx context.Context, req *proto.ExecTaskRequest) (*proto.ExecTaskResponse, error) {\n\ttimeout, err := ptypes.Duration(req.Timeout)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/drivers/server.go#L265-L301","documentation":"In the driver plugin server's TaskStats streaming handler, converting a driver's statistics frame to protobuf failed, so the stats stream is aborted mid-flight with the marshaling error wrapped.","triggerScenarios":"Thrown at plugins/drivers/server.go:283 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the driver's TaskStats implementation emits well-formed stats structs","Fix the field that fails TaskStatsToProto conversion (e.g. malformed resource usage data)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}