dianping/cat · warning · StaticWarning
W02
W02
Error message
"{uri}" already bound to the "{prefix}" prefix What it means
W02 is a StaticWarning that the same namespace URI is being bound again to a (new) prefix. After addNamespace() installs the new binding it checks whether a previous entry existed for that URI; if so it warns that the URI was already bound to the old prefix. Unlike XQST0047 this is not fatal — it just signals redundant or potentially confusing double binding.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1823
}
var namespace = this.getNamespace(uri);
if (namespace && namespace.type === type && type !== 'declare' && !namespace.override) {
throw new StaticError('XQST0047', '"' + uri + '": duplicate target namespace', pos);
}
namespace = this.getNamespaceByPrefix(prefix);
if (namespace && !namespace.override) {
throw new StaticError('XQST0033', '"' + prefix + '": namespace prefix already bound to "' + namespace.uri + '"', pos);
}
namespace = this.namespaces[uri];
this.namespaces[uri] = {
prefix: prefix,
pos: pos,
type: type
};
if (namespace) {
throw new StaticWarning('W02', '"' + uri + '" already bound to the "' + namespace.prefix + '" prefix', pos);
}
},
getNamespaces: function(){
return this.root.namespaces;
},
getNamespace: function (uri) {
var that = this;
while (that) {
var namespace = that.namespaces[uri];
if (namespace) {
return namespace;
}
that = that.parent;
}
View on GitHub (pinned to e815e74d4c)
Solutions
- Keep one prefix per namespace URI and delete the redundant declaration.
- If both prefixes are intentional aliases, accept the warning but document it to avoid reader confusion.
- Search the prolog for the URI string to find all competing declarations.
Example fix
// before declare namespace a = "http://example.org/mod"; declare namespace b = "http://example.org/mod"; // after declare namespace a = "http://example.org/mod";
Defensive patterns
Strategy: validation
Validate before calling
// Detect the same URI bound under two prefixes
var byUri = {};
bindings.forEach(function(b) {
if (byUri[b.uri] && byUri[b.uri] !== b.prefix) {
warn(b.uri + ' already bound as ' + byUri[b.uri]);
}
byUri[b.uri] = b.prefix;
}); Try / catch
if (e.name === 'StaticWarning' && e.code === 'W02') {
reportLint(e.pos, e.message);
} Prevention
- One URI, one prefix — enforce via code review or lint.
- During prefix migrations, remove old declarations in the same change.
When it happens
Trigger: 'declare namespace a = "U";' then 'declare namespace b = "U";' — the second addNamespace call finds the existing namespaces[uri] entry and warns, having already overwritten the binding.
Common situations: Copy-pasted prologs that alias the same module twice; teams standardizing on a new prefix while old code still declares the old one; refactors that add a 'cleaner' prefix without removing the old declaration.
Related errors
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/4d6b9ff6498136a9.
Report an issue: GitHub.