{"record":{"id":"d8276557859a27ec","repo":"dianping/cat","slug":"xqst0059","errorCode":"XQST0059","errorMessage":"module \"{uri}\" not found","messagePattern":"module \"(.+?)\" not found","errorType":"error_code","errorClass":"StaticError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":1788,"sourceCode":"        defaultElementNamespace: '',\n        namespaces: namespaces,\n        availableModuleNamespaces: [],\n        importModule: function(uri, prefix, pos) {\n            if(this !== this.root){\n                throw new Error('Function not invoked from the root static context.');\n            }\n            this.addNamespace(uri, prefix, pos, 'module');\n            if(this.moduleResolver) {\n                try {\n                    var mod = this.moduleResolver(uri, []);\n                    if(mod.variables) {\n                        TreeOps.concat(this.variables, mod.variables);\n                    }\n                    if(mod.functions) {\n                        TreeOps.concat(this.functions, mod.functions);\n                    }\n                } catch(e) {\n                    throw new StaticError('XQST0059', 'module \"' + uri + '\" not found', pos);\n                }\n            }\n            return this;\n        },\n        getAvailableModuleNamespaces: function(){\n            return this.root.availableModuleNamespaces;\n        },\n        getPrefixByNamespace: function(uri){\n            return this.root.namespaces[uri].prefix;\n        },\n        addNamespace: function (uri, prefix, pos, type) {\n            if(prefix === '' && type === 'module') {\n                throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);\n            }\n            if (uri === '') {\n                throw new StaticError('XQST0088', 'empty target namespace in module import or module declaration', pos);\n            }\n            var namespace = this.getNamespace(uri);","sourceCodeStart":1770,"sourceCodeEnd":1806,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L1770-L1806","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nimport module namespace xm = \"http://exist-db.org/xquery/test\";\n\n// after (URI matches the module declaration exactly)\nimport module namespace xm = \"http://exist-db.org/xquery/tests/util\";","handlingStrategy":"try-catch","validationCode":"// Before compiling, confirm the resolver can serve every imported URI\nvar imports = queryText.match(/import\\s+module\\s+namespace[^=]*=\\s*[\"']([^\"']+)[\"']/g) || [];\nimports.forEach(function(m) {\n  var uri = m.match(/[\"']([^\"']+)[\"']/)[1];\n  if (!moduleRegistry[uri]) { /* warn user before compile */ }\n});","typeGuard":"function isResolvableModuleUri(resolver, uri) {\n  try { return !!resolver(uri, []); } catch (e) { return false; }\n}","tryCatchPattern":"try {\n  worker.analyze(xquerySource);\n} catch (e) {\n  if (e.code === 'XQST0059') {\n    showDiagnostic('Module not found: check the import URI ' + e.message);\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["xquery","static-analysis","module-import","editor-worker"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}