dianping/cat · error · StaticError
XQST0048
XQST0048
Error message
"{prefix}:{name}": Qname not library namespace What it means
XQST0048 is raised when a variable is declared inside a library module but its QName is not in the module's own namespace. addVariable() checks VarDecl entries in a module context (moduleNamespace !== '') and requires qname.uri to equal moduleNamespace, or qname.uri === '' while the default function namespace equals the module namespace. Library module components must live in the module namespace.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1899
}
if(namespace) {
qname.uri = namespace.uri;
}
qname.name = value.substring(idx + 1);
}
return qname;
},
variables: {},
varRefs: {},
functionCalls: {},
addVariable: function(qname, type, pos){
if(
type === 'VarDecl' && this.moduleNamespace !== '' &&
!(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))
) {
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
}
var key = getVarKey(qname);
if(type === 'VarDecl' && this.variables[key]) {
throw new StaticError('XQST0049', '"' + qname.name + '": duplicate variable declaration', pos);
}
this.variables[key] = {
type: type,
pos: pos,
qname: qname,
annotations: {}
};
return this;
},
getVariables: function(){
var variables = {};
var that = this;
var handler = function(key){View on GitHub (pinned to e815e74d4c)
Solutions
- Prefix the variable with the module's own prefix: 'declare variable $m:foo ...'.
- Ensure the prefix used expands to exactly the module namespace URI.
- Or move shared variable declarations to the module that owns the namespace.
Example fix
// before (library module, namespace m = "http://example.org/m") declare variable $foo as xs:integer := 1; // after declare variable $m:foo as xs:integer := 1;
Defensive patterns
Strategy: validation
Validate before calling
// Library module lint: every declared variable must use the module prefix
if (isLibraryModule) {
var decls = source.match(/declare\s+variable\s+\$([\w-]+):/g) || [];
decls.forEach(function(d) {
var p = d.match(/\$(.+):/)[1];
if (p !== modulePrefix) { warn('Variable prefix must be ' + modulePrefix); }
});
} Type guard
function isInModuleNamespace(moduleNs, qname, defaultFnNs) {
return moduleNs === qname.uri ||
(qname.uri === '' && defaultFnNs === moduleNs);
} Try / catch
if (e.code === 'XQST0048') {
highlight(e.pos, 'Library module variables must use the module namespace prefix');
} Prevention
- When converting a main module to a library module, prefix every declared variable and function.
- Keep the module prefix consistent from 'module namespace' down to each declaration.
When it happens
Trigger: In a library module (module namespace m = "U"), writing 'declare variable $other:foo ...' where other maps to a different URI, or declaring an unprefixed variable while the default function namespace is not the module namespace.
Common situations: Converting a main module to a library module and forgetting to prefix declared variables; copy-pasting variable declarations from another module; declaring $m:foo but with a stale prefix bound to the wrong URI.
Related errors
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/6bc6b014bc25c28e.
Report an issue: GitHub.