dianping/cat · error · StaticError
XQST0059
XQST0059
Error message
module "{uri}" not found What it means
XQST0059 is the XQuery static error for a module import that cannot be resolved. In this editor worker, the static context calls the registered moduleResolver(uri, []) for an 'import module' declaration; if the resolver itself throws (unknown URI, load failure), the worker wraps it as StaticError XQST0059 'module "uri" not found'. Note the error reflects the resolver failing, not merely a missing module registry entry — if no moduleResolver is configured, no error is thrown at all.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1788
defaultElementNamespace: '',
namespaces: namespaces,
availableModuleNamespaces: [],
importModule: function(uri, prefix, pos) {
if(this !== this.root){
throw new Error('Function not invoked from the root static context.');
}
this.addNamespace(uri, prefix, pos, 'module');
if(this.moduleResolver) {
try {
var mod = this.moduleResolver(uri, []);
if(mod.variables) {
TreeOps.concat(this.variables, mod.variables);
}
if(mod.functions) {
TreeOps.concat(this.functions, mod.functions);
}
} catch(e) {
throw new StaticError('XQST0059', 'module "' + uri + '" not found', pos);
}
}
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);View on GitHub (pinned to e815e74d4c)
Solutions
- Verify the target namespace URI in the 'import module' statement matches the module declaration's URI exactly (case-sensitive, no trailing slash).
- Check the moduleResolver implementation wired into the worker to see why it throws for this URI and fix/extend its resolution logic.
- Confirm the module actually exists and is loadable from wherever the resolver fetches it (repo, classpath, REST endpoint).
- If the import is optional, remove it or guard the resolver so a failed load returns a stub with empty variables/functions instead of throwing.
Example fix
// before import module namespace xm = "http://exist-db.org/xquery/test"; // after (URI matches the module declaration exactly) import module namespace xm = "http://exist-db.org/xquery/tests/util";
Defensive patterns
Strategy: try-catch
Validate before calling
// Before compiling, confirm the resolver can serve every imported URI
var imports = queryText.match(/import\s+module\s+namespace[^=]*=\s*["']([^"']+)["']/g) || [];
imports.forEach(function(m) {
var uri = m.match(/["']([^"']+)["']/)[1];
if (!moduleRegistry[uri]) { /* warn user before compile */ }
}); Type guard
function isResolvableModuleUri(resolver, uri) {
try { return !!resolver(uri, []); } catch (e) { return false; }
} Try / catch
try {
worker.analyze(xquerySource);
} catch (e) {
if (e.code === 'XQST0059') {
showDiagnostic('Module not found: check the import URI ' + e.message);
} else { throw e; }
} Prevention
- Maintain a module registry keyed by namespace URI and validate imports against it before analysis.
- Normalize URIs (trim, no trailing slash) when registering and importing so lookups match.
- Log resolver failures with the requested URI to catch stale imports early.
When it happens
Trigger: An XQuery document contains 'import module namespace p = "some-URI";' and the moduleResolver callback throws for that URI (not registered, network fetch failed, or module source rejected). Only fires when this.moduleResolver is truthy.
Common situations: Typo in the module namespace URI; module removed/renamed on the server but the query still imports it; the resolver's whitelist not covering a newly added module; running the editor worker against a backend that no longer exposes the module endpoint.
Related errors
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/d8276557859a27ec.
Report an issue: GitHub.