Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  69] [ 5]  / answers: 1 / hits: 26660  / 12 Years ago, sun, december 9, 2012, 12:00:00

I'm using Node, Express with EJS view engine, nano (for couchdb), and I'm running into this pretty puzzling error which I cold not find any Node/JS specific info about via SO or Goog. The area of my code that seems to be triggering this involves nested async callbacks which grab a document from CouchDB, look through it for some matches, and push an object to an array in my private scope.



And the error:



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)

More From » node.js

 Answers
27

The error was a missing bracket on an if statement in my EJS template. As that trace shows, it was in the exports.compile function (which is called by res.render()) that this error occurs) - the lib author uses a string to create a new function, which encloses my EJS file functionality in a try block, which becomes a dangling try because my missing opening bracket in my if block caused a syntax error in the new anonymous function created as a string and built with new Function('str').



@T.J.Crowder pointed out, that stack trace is perfectly clear, and did ultimately lead to this solution. I removed some of my example code because it definitely wasn't linked to the ultimate problem.


[#81523] Friday, December 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
helenat

Total Points: 450
Total Questions: 95
Total Answers: 97

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
;