在尝试之后缺少捕获或最后

net*_*ica 3 javascript node.js express

我正在使用Node,Express和EJS视图引擎,nano(用于couchdb),我遇到了这个非常令人费解的错误,我很冷,没有找到关于通过SO或Goog的任何Node/JS特定信息.我的代码区域似乎触发了这个区域涉及嵌套的异步回调,它从CouchDB中获取文档,查看一些匹配项,并将对象推送到我的私有作用域中的数组.

而错误:

Express
500 SyntaxError: Missing catch or finally after try
at Object.Function (unknown source)
at exports.compile (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/ejs/lib/ejs.js:234:12)
at Object.exports.render (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/ejs/lib/ejs.js:273:10)
at View.exports.renderFile [as engine] (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/ejs/lib/ejs.js:303:22)
at View.render (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/express/lib/view.js:75:8)
at Function.app.render (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/express/lib/application.js:501:10)
at ServerResponse.res.render (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/express/lib/response.js:719:7)
at exports.dashboard.res.render.msg (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/routes/index.js:19:29)
at module.exports.read (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/api/Character.js:56:25)
at Request._callback (/Users/Keith/Desktop/netPoetica/1- Projects/dcc-chargen/node_modules/nano/nano.js:296:11)
Run Code Online (Sandbox Code Playgroud)

net*_*ica 11

该错误是我的EJS模板中if语句的缺失括号.正如该跟踪所示,它在exports.compile函数(由res.render()调用)中发生此错误) - lib作者使用字符串创建一个新函数,该函数将我的EJS文件功能封装在一个尝试阻止,这变成了悬空尝试,因为我的if块中缺少的开括号导致在作为字符串创建并使用"new Function('str')"构建的新匿名函数中出现语法错误.

@TJCrowder指出,堆栈跟踪非常清晰,最终导致了这个解决方案.我删除了一些我的示例代码,因为它肯定没有与最终问题相关联.


小智 5

对我而言,以下for循环中缺少{导致了错误。寻找适当的关闭或打开括号。

<% for(var i=0;i<users.length;i++) %>   
    <li> <%= users[i]   %>  </li>
    <%}%>
    </ul>
    </p>
Run Code Online (Sandbox Code Playgroud)