Ghost: Use first theme available if casper doesn't exist on first run.

Created on 28 Jan 2015  路  21Comments  路  Source: TryGhost/Ghost

Currently on first run, the server crashes if the casper theme is not present. I suggest using the first theme available if casper doesn't exist and only throwing if no themes are available.

Would this be desirable behavior? I can submit a PR if so.

help wanted server / core themes / frontend

Most helpful comment

@ErisDS I would like to submit a patch for LTS, but I haven't started any deep investigation yet. I saw that validation error appears during migrations and the whole initial setup is rolled back. I'm not sure if the next week is realistic for me to provide a ready solution, I will ping you asap I will find something on this topic.

I've signed up to your slack already, I will ping you there then.

All 21 comments

+1

+1

I believe I've run into this before and ended up just calling the theme casper as a workaround.

Definitely desirable behaviour, yes

Was going to post the same issue just now, but I decided to search through existing ones.

Here's the message I get for this issue:

     at /var/www/<directory>/source/node_modules/ghost/core/server/data/validation/index.js:116:35
     at tryCatch1 (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/util.js:45:21)
     at Promise._callHandler (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:571:13)
     at Promise._settlePromiseFromHandler (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:581:18)
     at Promise._settlePromiseAt (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:713:18)
     at Promise._settlePromiseAtPostResolution (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:335:10)
     at Async._consumeFunctionBuffer (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/async.js:85:12)
     at Async.consumeFunctionBuffer (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/async.js:40:14)
     at process._tickDomainCallback (node.js:492:13)
 Possibly unhandled Error
     at Error.ValidationError (/var/www/<directory>/source/node_modules/ghost/core/server/errors/validation-error.js:6:18)
     at /var/www/<directory>/source/node_modules/ghost/core/server/data/validation/index.js:116:35
     at tryCatch1 (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/util.js:45:21)
     at Promise._callHandler (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:571:13)
     at Promise._settlePromiseFromHandler (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:581:18)
     at Promise._settlePromiseAt (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:713:18)
     at Promise._settlePromiseAtPostResolution (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/promise.js:335:10)
     at Async._consumeFunctionBuffer (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/async.js:85:12)
     at Async.consumeFunctionBuffer (/var/www/<directory>/source/node_modules/ghost/node_modules/bluebird/js/main/async.js:40:14)
     at process._tickDomainCallback (node.js:492:13)

How should the "first available" theme be determined? Alphabetically seems more like a hack than a fix to me. Although, in these situations I can imagine you just want something to load wether you have one theme or 24, none of which called "casper".

Thinking out loud; what happens if you delete your selected theme? Do you get the same error? Does Ghost try to load "casper" or the selected theme if it's something other than "casper"?

Is there anyone more familiar with the core that would be willing to help me with this task?

If I try to start Ghost for the first time without any theme present, I get the following error:

@alecho it seems you get a different error? It would be interesting to track that down, as I think with the error I see the behaviour is at least relatively sane.

After the first run, if you try to start Ghost without the currently active theme then the frontend should throw an appropriate error: "The currently active theme casper is missing.". The admin panel should continue to function as per usual, which it currently does not. That is a regression and needs to be fixed, so I've raised that as a separate issue.

Making Ghost start up for the first time without casper needs some thought on the approach. Casper is set as the active theme via the default-settings.json, so there's no particular 'first run' behaviour in Ghost to do with the theme.

This could be changed to have a first-run specific piece of code to look for Casper first, and then fall back to any other available theme. I don't think there needs to be a strategy like 'alphabetical', just whatever is read first from the content/themes directory which is probably alphabetical anyway.

Sounds good to me. I was deploying Ghost with PM2 so I was looking the the logs it provides. The express server was failing to start with this error. This was on a "fresh" install so the setup process hadn't been done yet. That could be the difference between our experiences.

So, to recap, what I did was:

  1. Get a fresh copy of Ghost (via npm for me)
  2. Deleted casper theme (I had another installed)
  3. Start Ghost with PM2
  4. Scratch head as the process restarts every 45 seconds or so with error messages posted above in the output of pm2 logs <process id>

@alecho it looks very much to me like the first part of the error message is missing from what you provided?

It is. I haven't confirmed if that's from PM2 stripping it for some reason or if Ghost never output it to the log. However, I can confirm it wasn't there.

@ErisDS To clarify, every log message before what I posted was of the (out) level and looks normal (ex. out): 127.0.0.1 - - [14/Apr/2015:05:22:24 +0000] "GET /ghost/api/v0.1/notifications/ HTTP/1.0" 200 20 "...) while what I posted was everything of the (err) level.

I tried to replicate the problem by build master from scratch and renaming casper to foo.

Warning: Found a theme with no package.json file
 Theme name: foo
 This will be required in future. Please see http://docs.ghost.org/themes/

Ghost is running in development...
Listening on 127.0.0.1:2368
Url configured as: http://localhost:2368

Is this issue still relevant or can it be closed?

Does that server stay up indefinitely?

Yes, had it running for 20 minutes without problems.

Warning: Found a theme with no package.json file
 Theme name: foo
 This will be required in future. Please see http://docs.ghost.org/themes/

Ghost is running in development...
Listening on 127.0.0.1:2368
Url configured as: http://localhost:2368
Ctrl+C to shut down
GET / 200 226.466 ms - -
GET /welcome-to-ghost/ 200 207.160 ms - -
GET /author/ghost-owner/ 200 98.733 ms - -
^C
Ghost has shut down

Ghost was running for 1297 seconds

I am still able to reproduce the issue:

  • install Ghost fresh with a fresh DB
  • rename casper folder and in package.json
  • start ghost

You get the following:

The idea in this issue is, I think, to fallback to the first available (alphabetically I suppose) theme found in the theme folder, if casper is not available on first run.

@ErisDS Yes. Something needs to show so that another theme can be selected, if desired. My original expectation when I only had one theme in the folder was that the theme would be automatically selected.

I see this issue is addressed on the master branch: when the active theme is missing you can still use admin panel.

However, the landing page can not load some css and images, probably due to lack of fingerprint in the file names. For example it includes

/ghost/assets/ghost.css?v=582254a2eb

file, when it should something like

/ghost/assets/ghost-some-long-fingerprint-here.css

Effect:


it looks like this to me
screenshot 2017-03-25 13 19 32

--
On lts branch, server does not start at all when the active theme is missing.

Are you interested in being able to open admin panel for lts branch?

However, the landing page can not load some css and images, probably due to lack of fingerprint in the file names.

This is already covered in https://github.com/TryGhost/Ghost/issues/8126

@ertrzyiks The LTS branch should not be crashing if the active theme is missing, this is an unfortunate and constant regression. It's permanently fixed (I hope) In master, but if you fancy contributing a fix to the LTS branch that would be great. It is likely that the next LTS release would happen next week some time, so shout loud if you're working on something for it :)

P.S. You can find us all in slack

@ErisDS I would like to submit a patch for LTS, but I haven't started any deep investigation yet. I saw that validation error appears during migrations and the whole initial setup is rolled back. I'm not sure if the next week is realistic for me to provide a ready solution, I will ping you asap I will find something on this topic.

I've signed up to your slack already, I will ping you there then.

Now that we have Ghost CLI, this shouldn't really happen. There was an attempt at a fix for this issue, but it the fix was significantly more complex than I think is really warranted for such a case.

I am going to close this for now. If more people do run into this, I think the only reasonable fix is to add a configuration option for the name of the default theme, so that it can be overridden for people with this usecase.

1) Installing and using NODE v6.9.1 with nvm
2) and also I've installed sqlite as node dependency with npm 'npm install sqlite3 --save'

Worked for me :)

Was this page helpful?
0 / 5 - 0 ratings