MarkLogic、Gradle、DHF升级后单个代码库mlDeploy失败求助
问题分析:MarkLogic升级后mlDeploy失败的原因及解决办法
背景信息
我们完成了以下版本升级:
- MarkLogic:从10.0.7升级至11.0.0
- Gradle:从5.2.1升级至6.4
- DHF:从5.2.0升级至5.8.1
升级过程均成功,4个代码库中有3个的mlDeploy执行正常,但其中一个代码库执行mlDeploy失败,未升级环境中该操作无异常。
错误信息
Gradle错误输出
> Task :mlDeployApp FAILED :mlDeployApp (Thread[Daemon worker,5,main]) completed. Took 3 mins 16.45 secs. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':mlDeployApp'. > Error occurred while loading REST modules: Error occurred while loading modules; host: localhost; port: 8011; cause: Local message: config/resources write failed: Bad Request. Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid assemblySegmentation extension: could not parse JavaScript extension assemblySegmentation; please see the server error log for detail JS-JAVASCRIPT:     const bdsQuery = cts.andQuery([ -- Error running JavaScript request: SyntaxError: Unexpected identifier; assemblySegmentation either is not a valid JavaScript module or does not export functions (delete, get, put, post)
MarkLogic错误日志
2023-11-06 12:45:52.180 Notice:+ $body = document{text{"const segmentation = require('/custom-modules/segmentationLib..."}} 2023-11-06 12:45:52.777 Info: Status 500: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid assemblySegmentation extension: could not parse JavaScript extension assemblySegmentation; please see the server error log for detail JS-JAVASCRIPT: Â Â const bdsDocument = fn.head(cts.search(bdsQuery)); //bdsPublished Document -- Error running JavaScript request: SyntaxError: Unexpected identifier; assemblySegmentation either is not a valid JavaScript module or does not export functions (delete, get, put, post) 2023-11-06 12:45:53.320 Info: <error:error xsi:schemaLocation="http://marklogic.com/xdmp/error error.xsd" xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 2023-11-06 12:45:53.320 Info:+ <error:code>JS-JAVASCRIPT</error:code> 2023-11-06 12:45:53.320 Info:+ <error:name/> 2023-11-06 12:45:53.320 Info:+ <error:xquery-version>javascript</error:xquery-version> 2023-11-06 12:45:53.320 Info:+ <error:message>Error running JavaScript request</error:message> 2023-11-06 12:45:53.320 Info:+ <error:format-string>JS-JAVASCRIPT: Â Â const bdsDocument = fn.head(cts.search(bdsQuery)); //bdsPublished Document -- Error running JavaScript request: SyntaxError: Unexpected identifier</error:format-string> 2023-11-06 12:45:53.320 Info:+ <error:retryable>false</error:retryable> 2023-11-06 12:45:53.320 Info:+ <error:expr>Â Â const bdsDocument = fn.head(cts.search(bdsQuery)); //bdsPublished Document</error:expr> 2023-11-06 12:45:53.320 Info:+ <error:data> 2023-11-06 12:45:53.320 Info:+ <error:datum>SyntaxError: Unexpected identifier</error:datum> 2023-11-06 12:45:53.320 Info:+ </error:data> 2023-11-06 12:45:53.320 Info:+ <error:stack> 2023-11-06 12:45:53.320 Info:+ <error:frame> 2023-11-06 12:45:53.320 Info:+ <error:uri>/custom-modules/kcqty-lib/pbsEffLib.sjs</error:uri> 2023-11-06 12:45:53.320 Info:+ <error:line>525</error:line> 2023-11-06 12:45:53.320 Info:+ <error:column>7</error:column> 2023-11-06 12:45:53.320 Info:+ <error:xquery-version>javascript</error:xquery-version> 2023-11-06 12:45:53.320 Info:+ </error:frame> 2023-11-06 12:45:53.320 Info:+ <error:frame> 2023-11-06 12:45:53.320 Info:+ <error:uri>[anonymous]</error:uri> 2023-11-06 12:45:53.320 Info:+ <error:line>1</error:line> 2023-11-06 12:45:53.320 Info:+ <error:column>0</error:column> 2023-11-06 12:45:53.320 Info:+ <error:xquery-version>javascript</error:xquery-version> 2023-11-06 12:45:53.320 Info:+ </error:frame> 2023-11-06 12:45:53.320 Info:+ <error:frame> 2023-11-06 12:45:53.320 Info:+ <error:uri>/marklogic.rest.resource/pbsEff/assets/resource.sjs</error:uri> 2023-11-06 12:45:53.320 Info:+ <error:line>2</error:line> 2023-11-06 12:45:53.320 Info:+ <error:column>18</error:column> 2023-11-06 12:45:53.320 Info:+ <error:operation>xdmp:eval("require(&amp;quot;/marklogic.rest.resource/pbsEff/assets/resource.sj...")</error:operation> 2023-11-06 12:45:53.320 Info:+ <error:xquery-version>javascript</error:xquery-version> 2023-11-06 12:45:53.320 Info:+ </error:frame>
原因分析
- JavaScript语法校验严格化:MarkLogic 11对JavaScript解析引擎进行了升级,对ES6语法和代码规范性的校验比MarkLogic 10更严格。在旧版本中可以兼容的不规范语法(比如未正确声明变量、语法拼写错误),在新版本中会直接触发
SyntaxError。 - REST模块规范要求:错误提示提到
assemblySegmentation扩展不符合要求,说明该REST模块要么存在语法问题,要么没有正确导出MarkLogic REST扩展要求的函数(delete、get、put、post)。 - 具体错误位置:核心错误出现在
/custom-modules/kcqty-lib/pbsEffLib.sjs第525行第7列,该行的const bdsDocument = fn.head(cts.search(bdsQuery));语句存在意外标识符,导致语法解析失败。
解决方案
必须修改对应的.sjs文件,步骤如下:
- 定位到
/custom-modules/kcqty-lib/pbsEffLib.sjs第525行,检查该行及上下文的代码,修正语法错误(比如变量未正确定义、关键字误用、符号拼写错误等)。 - 检查
assemblySegmentation相关的REST模块代码,确保它正确导出了要求的函数(通过exports.delete、exports.get等方式暴露接口),符合MarkLogic REST扩展的规范。 - 全面验证所有自定义JavaScript模块的语法,确保代码符合ES6标准,移除MarkLogic 11不再兼容的旧语法。
内容的提问来源于stack exchange,提问作者Ashish Patil
相关产品推荐
相关产品推荐

