apache/hadoop · warning · BadRequestException
tasktype must be either m or r
Error message
tasktype must be either m or r
What it means
Thrown by the JobHistoryServer REST endpoint GET /ws/v1/history/mapreduce/jobs/{jobid}/tasks?type=... when the type value is not exactly 'm' or 'r'. The handler calls MRApps.taskType(type), which only maps the single-character symbols 'm' (map) and 'r' (reduce) and throws YarnRuntimeException for anything else; HsWebServices converts that to a BadRequestException (HTTP 400).
Source
Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java:350
@GET
@Path("/mapreduce/jobs/{jobid}/tasks")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public TasksInfo getJobTasks(@Context HttpServletRequest hsr,
@PathParam("jobid") String jid, @QueryParam("type") String type) {
init();
Job job = AMWebServices.getJobFromJobIdString(jid, ctx);
checkAccess(job, hsr);
TasksInfo allTasks = new TasksInfo();
for (Task task : job.getTasks().values()) {
TaskType ttype = null;
if (type != null && !type.isEmpty()) {
try {
ttype = MRApps.taskType(type);
} catch (YarnRuntimeException e) {
throw new BadRequestException("tasktype must be either m or r");
}
}
if (ttype != null && task.getType() != ttype) {
continue;
}
allTasks.add(new TaskInfo(task));
}
return allTasks;
}
@GET
@Path("/mapreduce/jobs/{jobid}/tasks/{taskid}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public TaskInfo getJobTask(@Context HttpServletRequest hsr,
@PathParam("jobid") String jid, @PathParam("taskid") String tid) {
init();View on GitHub (pinned to 2add963021)
Solutions
- Use exactly type=m or type=r (lowercase single character)
- Omit the type parameter to list all tasks of both kinds
- Map friendly names to symbols before building the URL
Example fix
# before curl "http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks?type=map" # after curl "http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks?type=m"
Defensive patterns
Strategy: validation
Validate before calling
static String taskTypeSymbol(String input) {
if (input == null || input.isEmpty()) return null; // no filter
if (input.equalsIgnoreCase("m") || input.equalsIgnoreCase("map")) return "m";
if (input.equalsIgnoreCase("r") || input.equalsIgnoreCase("reduce")) return "r";
throw new IllegalArgumentException("type must be m or r: " + input);
} Prevention
- Map user-facing words (map/reduce) to m/r in one helper used by every call site
- The check is case- and spelling-exact: 'M', 'MAP', 'mapper' all fail
- Omit type to get both task kinds, then filter client-side if unsure
When it happens
Trigger: GET /ws/v1/history/mapreduce/jobs/{jobid}/tasks?type=map, type=MAP, type=reduce, type=mapper, or any string other than exactly 'm' or 'r'. An empty value is treated as 'no filter' and does not trigger this.
Common situations: Passing the full word because the same API family (AM web services) documents type as m|r but users assume words; Case mismatch: 'M'/'R' are rejected — the check is case-sensitive; Scripts templating type=${TASK_KIND} where TASK_KIND is 'map' from other tooling
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- startedTimeEnd must be greater than 0
- startedTimeEnd must be greater than startTimeBegin
- finishedTimeBegin must be greater than 0
- finishedTimeEnd must be greater than 0
- finishedTimeEnd must be greater than finishedTimeBegin
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/57a29073b314642e.
Report an issue: GitHub.