alibaba/arthas · error · ApiException
parse request failed: {}
Error message
parse request failed: {} What it means
Thrown by HttpApiHandler.parseRequest when JSON.parseObject fails to deserialize the request body into an ApiRequest. The underlying exception message (fastjson parse error) is appended, indicating the specific JSON syntax problem.
Source
Thrown at core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java:112
byte[] jsonBytes = JSON.toJSONBytes(result, JSON_FILTERS);
// create http response
DefaultFullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(),
HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonBytes));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=utf-8");
return response;
}
private ApiRequest parseRequest(String requestBody) throws ApiException {
if (StringUtils.isBlank(requestBody)) {
throw new ApiException("parse request failed: request body is empty");
}
try {
//ObjectMapper objectMapper = new ObjectMapper();
//return objectMapper.readValue(requestBody, ApiRequest.class);
return JSON.parseObject(requestBody, ApiRequest.class);
} catch (Exception e) {
throw new ApiException("parse request failed: " + e.getMessage(), e);
}
}
private ApiResponse processRequest(ChannelHandlerContext ctx, ApiRequest apiRequest) {
String actionStr = apiRequest.getAction();
try {
if (StringUtils.isBlank(actionStr)) {
throw new ApiException("'action' is required");
}
ApiAction action;
try {
action = ApiAction.valueOf(actionStr.trim().toUpperCase());
} catch (IllegalArgumentException e) {
throw new ApiException("unknown action: " + actionStr);
}
//no session requiredView on GitHub (pinned to 21cf2e9ba5)
Solutions
- Validate the JSON with a linter before sending.
- Use double quotes for all keys and string values (strict JSON, not JS object literals).
- Read the appended exception message — it pinpoints the parse failure location (e.g. 'unclosed string', 'unexpected token').
- Ensure the body is complete and not truncated by a proxy timeout.
Example fix
# before: single quotes + trailing comma (invalid JSON)
curl -X POST http://localhost:8563/api \
-d "{'action':'exec',}"
# -> parse request failed: ... unexpected token...
# after: valid strict JSON
curl -X POST http://localhost:8563/api \
-H 'Content-Type: application/json' \
-d '{"action":"exec","command":"version"}' Defensive patterns
Strategy: validation
Validate before calling
// Client-side: validate JSON before sending
try {
Object parsed = new JSONParser().parse(requestBody);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid JSON: " + e.getMessage());
} Prevention
- Use a JSON library to serialize requests rather than hand-writing JSON strings.
- Use double quotes for all keys and string values.
- Validate JSON with a linter during development.
When it happens
Trigger: The request body contains malformed JSON (trailing comma, unquoted keys, single quotes, truncated payload) or a structure that does not map to ApiRequest fields, causing fastjson to throw.
Common situations: Hand-written JSON with syntax errors. Encoding issues (BOM, wrong charset). Truncated bodies from network issues. Using single quotes instead of double quotes.
Related errors
- parse request failed: request body is empty
- Conversion from JSON to {type} failed
- Cannot convert to char: {value}
- '{s}' is not a valid size. Should be numeric value followed
- '{s}' is not a valid timespan. Shoule be numeric value follo
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/f0cf7dd4b25d7b3a.
Report an issue: GitHub.