dianping/cat · error · Error
invalid tagName:{tagName}
Error message
invalid tagName:{tagName} What it means
ElementAttributes.setTagName (worker-xml.js:1791-1796) validates each parsed tag name against tagNamePattern (built from nameStartChar/nameChar regexes, line 1338) and throws if it doesn't match. The pattern encodes the XML Name production: must start with a letter, '_', or ':', followed by name characters — so names beginning with a digit, or containing spaces/'='/'"', are rejected.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xml.js:1794
if(end){
var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
if(match){
var len = match[0].length;
domBuilder.processingInstruction(match[1], match[2]) ;
return end+2;
}else{//error
return -1;
}
}
return -1;
}
function ElementAttributes(source){
}
ElementAttributes.prototype = {
setTagName:function(tagName){
if(!tagNamePattern.test(tagName)){
throw new Error('invalid tagName:'+tagName)
}
this.tagName = tagName
},
add:function(qName,value,offset){
if(!tagNamePattern.test(qName)){
throw new Error('invalid attribute:'+qName)
}
this[this.length++] = {qName:qName,value:value,offset:offset}
},
length:0,
getLocalName:function(i){return this[i].localName},
getOffset:function(i){return this[i].offset},
getQName:function(i){return this[i].qName},
getURI:function(i){return this[i].uri},
getValue:function(i){return this[i].value}
}
View on GitHub (pinned to e815e74d4c)
Solutions
- Rename the element so it starts with a letter or underscore and contains only name characters (letters, digits, '-', '_', '.', ':').
- If the reported 'tagName' contains spaces or '=', the real bug is earlier in the tag — fix the malformed attribute that made the slice too long.
- Validate with xmllint to catch the root malformed tag.
Example fix
<!-- before --> <2col-layout>...</2col-layout> <!-- after --> <col-layout-2>...</col-layout-2>
Defensive patterns
Strategy: validation
Validate before calling
// Reuse the worker's own pattern shape to pre-validate tag names:
const NAME = /^[A-Za-z_:][-A-Za-z0-9_:.]*$/;
function tagNameOk(name) { return NAME.test(name); }
tagNameOk('col-2'); // true
tagNameOk('2col'); // false Type guard
function isValidXmlName(s) {
return typeof s === 'string' && /^[A-Za-z_:][-A-Za-z0-9_:.]*$/.test(s);
} Try / catch
try {
el.setTagName(name);
} catch (ex) {
if (/invalid tagName/.test(ex.message)) reportXmlError(ex); else throw ex;
} Prevention
- Tag names start with a letter or '_'; never a digit or '-'.
- If the reported name contains spaces/quotes, suspect a broken attribute earlier in the tag.
- Validate names with isValidXmlName() before generating elements programmatically.
When it happens
Trigger: Start tags like '<1abc>', '<-foo>', '<foo bar>' (space makes the slice 'foo bar' invalid), or names with invalid punctuation. The setTagName call from the '/'/'>' cases passes the sliced text to the test and throws at line 1793-1795.
Common situations: Tag-name/attribute boundary confusion from a missing quote or '=' earlier in the tag, CMS-generated pseudo-tags, template placeholders as tag names, or HTML custom-element names with unusual characters.
Related errors
- attribute equal must after attrName
- attribute value must after "="
- attribute invalid close char('/')
- attribute value missed!!
- elements closed character '/' and '>' must be connected to
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/060b8e727f83bfc9.
Report an issue: GitHub.