iflytek/astron-agent · error · RuntimeException
WeChat message parsing failed
Error message
WeChat message parsing failed
What it means
WechatMessageParser.parseXmlToMap parses a WeChat XML message into a Map via a DOM parser. Any exception during parsing (malformed XML, IO problems, parser configuration) is caught, logged with the offending content, and rethrown as RuntimeException('WeChat message parsing failed', e). Callers include dataMap, parseSystemMessage and parseUserMessage, so any of those message-processing paths surface this error.
Solutions
- Log/inpect the xmlContent in the error log to see exactly what failed to parse.
- Read the request body with the correct charset (WeChat sends UTF-8) before parsing.
- Validate/reject obviously non-XML payloads before invoking the parser (content sniffing or try/catch returning 400).
- Check for truncated or wrapped bodies caused by gateways/body-caching filters, and examine getCause() for the underlying SAXException.
Example fix
// before
String xml = new String(bodyBytes); // platform default charset
// after
String xml = new String(bodyBytes, StandardCharsets.UTF_8);
if (!xml.trim().startsWith("<")) {
throw new IllegalArgumentException("not a WeChat XML message");
} Defensive patterns
Strategy: validation
Validate before calling
if (xmlContent == null || !xmlContent.trim().startsWith("<")) throw new IllegalArgumentException("not XML"); Try / catch
try { return parser.parseXmlToMap(xml); } catch (RuntimeException e) { log.warn("bad callback xml: {}", xml); return ResponseEntity.badRequest().build(); } Prevention
- Read request bodies as UTF-8
- Reject non-XML payloads at the controller boundary
- Check getCause() for the underlying SAXException
- Watch for proxies truncating or wrapping bodies
When it happens
Trigger: Calling parseXmlToMap (directly or via parseSystemMessage/parseUserMessage/dataMap) with XML that fails DOM parsing — unclosed tags, invalid characters/encoding, non-XML bodies, or empty strings.
Common situations: Receiving non-XML payloads (JSON, form data, garbage from scanners/bots) at the WeChat callback endpoint; encoding mismatches (request read with the wrong charset, e.g. missing UTF-8); truncated bodies due to proxy limits; XML with features the parser rejects (DOCTYPE/entities).
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/cafa22817279359c.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/wechat/WechatMessageParser.java:129
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i) instanceof Element) {
Element element = (Element) childNodes.item(i);
result.put(element.getTagName(), element.getTextContent());
}
}
} else {
// Only parse specified fields
for (String field : targetFields) {
NodeList nodeList = root.getElementsByTagName(field);
if (nodeList.getLength() > 0) {
result.put(field, nodeList.item(0).getTextContent());
}
}
}
} catch (Exception e) {
log.error("Failed to parse WeChat XML message: {}", xmlContent, e);
throw new RuntimeException("WeChat message parsing failed", e);
}
return result;
}
}
View on GitHub (pinned to 5e758547a8)