{"record":{"id":"f0cf7dd4b25d7b3a","repo":"alibaba/arthas","slug":"parse-request-failed","errorCode":null,"errorMessage":"parse request failed: {}","messagePattern":"parse request failed: (.+?)","errorType":"http","errorClass":"ApiException","httpStatus":200,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java","lineNumber":112,"sourceCode":"        byte[] jsonBytes = JSON.toJSONBytes(result, JSON_FILTERS);\n\n        // create http response\n        DefaultFullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(),\n                HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonBytes));\n        response.headers().set(HttpHeaderNames.CONTENT_TYPE, \"application/json; charset=utf-8\");\n        return response;\n    }\n\n    private ApiRequest parseRequest(String requestBody) throws ApiException {\n        if (StringUtils.isBlank(requestBody)) {\n            throw new ApiException(\"parse request failed: request body is empty\");\n        }\n        try {\n            //ObjectMapper objectMapper = new ObjectMapper();\n            //return objectMapper.readValue(requestBody, ApiRequest.class);\n            return JSON.parseObject(requestBody, ApiRequest.class);\n        } catch (Exception e) {\n            throw new ApiException(\"parse request failed: \" + e.getMessage(), e);\n        }\n    }\n\n    private ApiResponse processRequest(ChannelHandlerContext ctx, ApiRequest apiRequest) {\n\n        String actionStr = apiRequest.getAction();\n        try {\n            if (StringUtils.isBlank(actionStr)) {\n                throw new ApiException(\"'action' is required\");\n            }\n            ApiAction action;\n            try {\n                action = ApiAction.valueOf(actionStr.trim().toUpperCase());\n            } catch (IllegalArgumentException e) {\n                throw new ApiException(\"unknown action: \" + actionStr);\n            }\n\n            //no session required","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-written JSON with syntax errors. Encoding issues (BOM, wrong charset). Truncated bodies from network issues. Using single quotes instead of double quotes.","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."],"exampleFix":"# before: single quotes + trailing comma (invalid JSON)\ncurl -X POST http://localhost:8563/api \\\n  -d \"{'action':'exec',}\"\n# -> parse request failed: ... unexpected token...\n\n# after: valid strict JSON\ncurl -X POST http://localhost:8563/api \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"action\":\"exec\",\"command\":\"version\"}'","handlingStrategy":"validation","validationCode":"// Client-side: validate JSON before sending\ntry {\n    Object parsed = new JSONParser().parse(requestBody);\n} catch (ParseException e) {\n    throw new IllegalArgumentException(\"Invalid JSON: \" + e.getMessage());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["http-api","json","parsing"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}