CloudyKangaroo / puppet-cloudykangaroo

Service Provider Management w/Sensu, Puppet and Ubersmith
http://cloudykangaroo.github.io/cloudykangaroo/
MIT License
4 stars 5 forks source link

Errors in Jade need to be handled gracefully #14

Open johann8384 opened 10 years ago

johann8384 commented 10 years ago

debug: redis returned value family=devices, token=deviceID, value=103888, type=applog, username=none, eventID=1c65848e-f260-42ec-8ed3-24b7d76a6352, requestID=none, sessionID=none TypeError: /Users/jonathan/WebstormProjects/cloudykangaroo/views/ubersmith/device.jade:88 86| span.pull-right #{uberDevice.parent_desc} 87| p Management:

88| span.pull-right #{uberDevice.metadata.management_level} 89| p Company: 90| span.pull-right 91| a(href="/ubersmith/clients/clientid/#{uberDevice.clientid}") #{uberDevice.listed_company}

Cannot read property 'management_level' of undefined at eval (eval at (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/jade/lib/jade.js:160:8), :1066:62) at res (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/jade/lib/jade.js:161:38) at Object.exports.render (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/jade/lib/jade.js:257:10) at Object.exports.renderFile (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/jade/lib/jade.js:293:18) at View.exports.renderFile as engine at View.render (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/express/lib/view.js:76:8) at Function.app.render (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/express/lib/application.js:504:10) at ServerResponse.res.render (/Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/express/lib/response.js:798:7) at /Users/jonathan/WebstormProjects/cloudykangaroo/routes/ubersmith.js:86:23 at /Users/jonathan/WebstormProjects/cloudykangaroo/node_modules/async/lib/async.js:229:13

rmc3 commented 10 years ago

From http://stackoverflow.com/questions/5567546/express-and-jade-ignore-render-errors , and similar posts, it appears that Jade does not have the built in ability to discard a variable in a template if it is undefined. It looks like the the most feasible (if somewhat onerous) option is to wrap all variables in Jade templates in

if typeof(msg) !== 'undefined'
    p #{msg}

I'm adding a function that will check if a variable is defined, return the string contents of the variable if so, or return an empty string if not. I'll then wrap all of the variable insertions in the Jade templates with it.

It might work.

rmc3 commented 10 years ago

From Jonathan, on what I assume was the wrong issue:

I tried out this method, ensure all used variables are defaulted in the route, but I'm not super happy with it. It has a maintenance burden also.

https://github.com/Contegix/cloudykangaroo/blob/breaking_it_all/routes/ubersmith.js#L96

It sounds like neither of us have an acceptable solution from a maintainability standpoint right now. However, https://github.com/Contegix/cloudykangaroo/commit/7ba2b24af997322f0c6b597a29559ed54641cae7 reflects what I described in my previous comment.

EDIT: Actually, it looks like I applied the regex that inserted that twice, so that commit is actually fairly broken. Still, it reflects my concept.

johann8384 commented 10 years ago

Sounds good, yeah I guess I put it on the wrong issue :)

This isn't too big of an issue right now, but yeah we should find something. On Jan 22, 2014 4:40 PM, "rmc3" notifications@github.com wrote:

From Jonathan, on what I assume was the wrong issue:

I tried out this method, ensure all used variables are defaulted in the route, but I'm not super happy with it. It has a maintenance burden also.

https://github.com/Contegix/cloudykangaroo/blob/breaking_it_all/routes/ubersmith.js#L96

It sounds like neither of us have an acceptable solution from a maintainability standpoint right now. However, 7ba2b24https://github.com/Contegix/cloudykangaroo/commit/7ba2b24af997322f0c6b597a29559ed54641cae7reflects what I described in my previous comment.

— Reply to this email directly or view it on GitHubhttps://github.com/Contegix/cloudykangaroo/issues/14#issuecomment-33077203 .