dianping/cat · error · StaticError

XQST0047

XQST0047

Error message

"{uri}": duplicate target namespace

What it means

XQST0047 is thrown when the same target namespace URI is imported/declared twice with the same type. addNamespace() looks up the URI in the scope chain; if an existing entry has the same type, the type is not 'declare', and the entry is not marked override, the second binding is rejected as a duplicate target namespace.

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1808

            }
            return this;
        },
        getAvailableModuleNamespaces: function(){
            return this.root.availableModuleNamespaces;
        },
        getPrefixByNamespace: function(uri){
            return this.root.namespaces[uri].prefix;
        },
        addNamespace: function (uri, prefix, pos, type) {
            if(prefix === '' && type === 'module') {
                throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);
            }
            if (uri === '') {
                throw new StaticError('XQST0088', 'empty target namespace in module import or module declaration', pos);
            }
            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);
            }

        },

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Delete one of the duplicate import declarations and keep a single prefix for that namespace.
  2. If different prefixes are genuinely needed, check whether the existing entry supports override before relying on rebinding.
  3. Remember 'declare' bindings (e.g. declare namespace) do not conflict with imports of the same URI — only same-type duplicates do.

Example fix

// before
import module namespace a = "http://example.org/mod";
import module namespace b = "http://example.org/mod";

// after
import module namespace a = "http://example.org/mod";
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check a prolog for duplicate same-type namespace targets
var seen = {};
prologImports.forEach(function(imp) {
  var key = imp.type + '|' + imp.uri;
  if (seen[key]) { warn('Duplicate ' + imp.type + ' of ' + imp.uri); }
  seen[key] = true;
});

Try / catch

if (e.code === 'XQST0047') {
  highlight(e.pos, 'Namespace already imported — remove the duplicate import');
}

Prevention

When it happens

Trigger: Two 'import module namespace a = "U";' and 'import module namespace b = "U";' statements, or the same module imported twice under different prefixes; also duplicate schema imports of the same namespace.

Common situations: Merged query files that each import the same module; copy-paste duplication; refactoring that adds an import without checking existing ones at the top of the prolog.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/bffd118235d988b5. Report an issue: GitHub.