Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail gracefully #16

Open
Fauntleroy opened this issue Dec 18, 2013 · 1 comment
Open

Fail gracefully #16

Fauntleroy opened this issue Dec 18, 2013 · 1 comment

Comments

@Fauntleroy
Copy link
Contributor

Right now many helpers will completely break template rendering if they don't get data of the correct type. Ideally this should just return nothing (from the helper), rather than destroy the whole page render.

@pushred
Copy link

pushred commented Jan 26, 2014

I ran into this today briefly in production.. I think resource data was probably missing temporarily as subsequent deploys cleared it up. One thing I noticed is that the message indicates no valid ISO 8601 time. This was a Twitter resource however which features their non-standard datetimes, i.e. Sun Jan 26 00:52:40 +0000 2014. That format is supported by the helper but might want to add a test as this one isn't quite the same.

TypeError: Object function (string) {
    var match;
    if (typeof string.getTime === "function")
        return string;
    else if (match = string.match(/^(\d{4})(-?(\d{2})(-?(\d{2})(T(\d{2}):?(\d{2})(:?(\d{2})(\.(\d+))?)?(Z|((\+|-)(\d{2}):?(\d{2}))))?)?)?$/)) {
        var date = new Date(
            Number(match[1]), // year
            (Number(match[3]) - 1) || 0, // month
            Number(match[5]) || 0, // day
            Number(match[7]) || 0, // hour
            Number(match[8]) || 0, // minute
            Number(match[10]) || 0, // second
            Number(match[12]) || 0);

        if (match[13] && match[13] !== "Z") {
            var h = Number(match[16]) || 0,
                m = Number(match[17]) || 0;

            h *= 3600000;
            m *= 60000;

            var offset = h + m;
            if (match[15] == "+")
                offset = -offset;

            date = new Date(date.valueOf() - offset);
        }

        return date;
    } else
        throw new Error("Invalid ISO 8601 date given.", __filename);
} has no method 'is'
    at newDate (/mnt/data/2/node_modules/solidus/node_modules/handlebars-helper/node_modules/new-date/lib/index.js:20:15)
    at Object.module.exports (/mnt/data/2/node_modules/solidus/node_modules/handlebars-helper/lib/helpers/formatDate.js:6:13)
    at program1 (eval at <anonymous> (/mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/compiler/compiler.js:579:23), <anonymous>:17:98)
    at program (/mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/runtime.js:77:14)
    at Object.each (/mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/base.js:116:21)
    at Object.<anonymous> (/mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/base.js:65:33)
    at Object.eval (eval at <anonymous> (/mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/compiler/compiler.js:579:23), <anonymous>:23:210)
    at /mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/runtime.js:38:33
    at /mnt/data/2/node_modules/solidus/node_modules/handlebars/lib/handlebars/compiler/compiler.js:1294:21
    at ExpressHandlebars.extend._renderTemplate (/mnt/data/2/node_modules/solidus/node_modules/express3-handlebars/lib/express-handlebars.js:307:22)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants