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

Empty partials cause error 500 #1964

Closed
bondarewicz opened this issue Jan 16, 2014 · 14 comments
Closed

Empty partials cause error 500 #1964

bondarewicz opened this issue Jan 16, 2014 · 14 comments
Assignees
Labels
bug [triage] something behaving unexpectedly
Milestone

Comments

@bondarewicz
Copy link

Since 0.4 there is an exception thrown on main index page:

You must pass a string or Handlebars AST to Handlebars.compile. You passed function (context, options) { if (!compiled) { compiled = compileInput(); } return compiled.call(this, context, options); }

Occurs when one of below custom/partials is blank:
https://github.com/oswaldoacauan/ghostium/tree/master/src/partials/custom

Exception is thrown here:

// If the partial view is not compiled, it compiles and saves in handlebars
    if (typeof partial === 'string') {
        partial = hbs.handlebars.compile(partial);
        hbs.handlebars.partials[name] = partial;
    }

if (typeof partial === 'string') {

Adding below to an empty partial fixes an issue:

{{! any comment here }}
  • Ghost Version: master (latest commit: c82d2ea)
  • Server OS: Archlinux, Ubuntu 13.04, OSX 10.8.5
  • Node Version: 0.10

Original issue reported here

@mgutz
Copy link

mgutz commented Jan 16, 2014

I was able to reproduce this problem and the fix seems to be to upgrade to latest express-hbs which can be tried by

npm install express-hbs@0.7.0-pre

in the Ghost directory. I fixed a long standing production cache issue. Let me know if that fixes it and I can make a 0.7.0 release.

@ErisDS
Copy link
Member

ErisDS commented Jan 16, 2014

@bondarewicz When raising issues here on GitHub, please take a few minutes to read the contributing guidelines. They provide tips on the kind of information to put into an issue. Raising issues with just one or two lines leaves a lot of work for the people reading this to go and find out what you're talking about.

@mgutz Thanks for coming and updating us about 0.7.0-pre.

Is anyone able to give this a thorough test?

@ErisDS
Copy link
Member

ErisDS commented Jan 17, 2014

@bondarewicz Much appreciate the updated issue 👍

I can see 2 different issues here, both related to empty partials..

With the Ghostium theme, Ghost throws a 500 error page:

ghostium

With the Rolls Royce theme Ghost just throws an ugly error message in the console, and never renders the frontend, which is really strange.

rollsroyce

So firstly, we need to fix it so that no matter what happens, Ghost renders it's 500 error page, and then we should introduce @mgutz's express-hbs fix to resolve the underlying issue with partials in production mode.

@roycehaynes
Copy link

I'm looking into this issue, but looks like an error message occurs in testing environment too. See image:

screen shot 2014-01-19 at 7 49 09 pm

cc: @ErisDS

@roycehaynes
Copy link

@mgutz - I did a thorough test with RollsRoyce theme, node v0.10.24, express-hbs@0.7.0-pre, and no success. The issue still occurs. Can you point me to the fix in the express-hbs repo?

@mgutz
Copy link

mgutz commented Jan 20, 2014

The tests for the original issue was an empty partial: https://github.com/barc/express-hbs/blob/master/test/issues.js#L10-L36

Your error seems different. How can I reproduce? Is it as simple as downloading the RollsRoyce theme and running in --production mode?

@ErisDS
Copy link
Member

ErisDS commented Jan 20, 2014

@mgutz @roycehaynes The rollsroyce theme is behaving VERY strangely.

In this case the partials are not empty, they contain a comment, and no newline afterwards. The error also is not caught properly. In order to fix the theme for people on the hosted service I'm having to add newlines after the comments in the 3 partials that only contain comments (github_handle.hbs, gravatar_url.hbs and twitter_handle.hbs). I've no idea why this fixes it, but it does.

This does seem to be a different problem. It occurs in development mode as well as production mode.

The problem that @roycehaynes is reporting here is yet another problem where partials are not found. I'm not sure why that would be happening. I ran into this whilst debugging, but wasn't sure what caused it. After changing permissions and switching themes a few times it seemed to work ok again.

@mgutz
Copy link

mgutz commented Jan 20, 2014

From the code above ghost is loading partials independently of express-hbs. This seems like a timing problem where the partial has not been cached before the template is rendered. I'll look tonight.

@mgutz
Copy link

mgutz commented Jan 21, 2014

There's definitely a bug in Handlebars when handling comment only partials '{{! comment}}'. They fixed something handlebars-lang/handlebars.js#675 about a month ago but it seems to to only fix it for an empty string, not the case where a partial results in an empty string.

As users have said, the fix is to add a space or a newline after the comment. I put a workaround in express-hbs@0.7.2-pre registerPartial for this situation. Note that this ghost code and other code where partials are compiled should be changed to use hbs.registerPartial() instead of setting partials directly.

@roycehaynes
Copy link

@mgutz - What do you mean when you say the partials are loading independently of express-hbs?

As far as the RollsRoyce theme goes, I updated and removed all references to partials. Now the partials are explicitly in the default.hbs file.

More thoughts on this in another message, but there needs to be a way to provide custom variables within a template that can be set via a config file. I'll look to see if a issue exists for this type of behavior/implementation.

@mgutz
Copy link

mgutz commented Jan 21, 2014

@roycehaynes The code above in the first message is settting partials directly on the handlebars.partials hash outside of express-hbs library bypassing the workaround I put in place.

Normal express apps use app.locals for global locals. Maybe ghost can provide a theme init hook for your needs.

@ErisDS
Copy link
Member

ErisDS commented Jan 22, 2014

@mgutz I tested pre-2 along with changing the code in Ghost to use registerPartials and could no longer reproduce any errors 👍 . I also submitted a PR to add some more error handling, would be great to get this on npm and then I will update Ghost.

@mgutz
Copy link

mgutz commented Jan 22, 2014

working on the other issues, hope to release later today

@ErisDS
Copy link
Member

ErisDS commented Jan 23, 2014

I have tested with 0.7.5 of express-hbs and am not seeing these errors anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly
Projects
None yet
Development

No branches or pull requests

4 participants