2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

🐛 Fixed showing "theme missing" error incorrectly (#9129)

closes #8222

- There are still some cases where Ghost shows "the currently active theme X is missing" when it isn't
- This is due to the error handling masking several cases
- This PR resolves that, ensuring errors from gscan and the underlying environment don't get masked
This commit is contained in:
Hannah Wolfe 2017-10-11 14:19:12 +01:00 committed by Katharina Irrgang
parent 94ac1c5998
commit c25c5e2395
2 changed files with 20 additions and 7 deletions

View file

@ -33,7 +33,7 @@ module.exports = {
// Validate
return validate
.check(theme)
.then(function resultHandler(checkedTheme) {
.then(function validationSuccess(checkedTheme) {
// CASE: inform that the theme has errors, but not fatal (theme still works)
if (checkedTheme.results.error.length) {
logging.warn(new errors.ThemeValidationError({
@ -46,7 +46,7 @@ module.exports = {
debug('Activating theme (method A on boot)', activeThemeName);
self.activate(theme, checkedTheme);
})
.catch(function (err) {
.catch(function validationFailure(err) {
if (err.errorDetails) {
logging.error(new errors.ThemeValidationError({
message: i18n.t('errors.middleware.themehandler.invalidTheme', {theme: activeThemeName}),
@ -56,13 +56,18 @@ module.exports = {
// CASE: we have to remember to show errors on blog
// `err.context` remembers the theme inside this property
active.set(theme, err.context, err);
self.activate(theme, err.context, err);
});
})
.catch(function (err) {
.catch(errors.NotFoundError, function (err) {
// CASE: active theme is missing, we don't want to exit because the admin panel will still work
err.message = i18n.t('errors.middleware.themehandler.missingTheme', {theme: activeThemeName});
logging.error(err);
})
.catch(function (err) {
// CASE: theme threw an odd error, we don't want to exit because the admin panel will still work
// This is the absolute catch-all, at this point, we do not know what went wrong!
logging.error(err);
});
},
// Load themes, soon to be removed and exposed via specific function.
@ -77,10 +82,17 @@ module.exports = {
validate: validate,
toJSON: require('./to-json'),
getActive: active.get,
activate: function activate(loadedTheme, checkedTheme) {
activate: function activate(loadedTheme, checkedTheme, error) {
// no need to check the score, activation should be used in combination with validate.check
// Use the two theme objects to set the current active theme
active.set(loadedTheme, checkedTheme);
try {
active.set(loadedTheme, checkedTheme, error);
} catch (err) {
logging.error(new errors.InternalServerError({
message: i18n.t('errors.middleware.themehandler.activateFailed', {theme: loadedTheme.name}),
err: err
}));
}
},
middleware: require('./middleware')
};

View file

@ -107,7 +107,8 @@
"themehandler": {
"missingTheme": "The currently active theme \"{theme}\" is missing.",
"invalidTheme": "The currently active theme \"{theme}\" is invalid.",
"themeHasErrors": "The currently active theme \"{theme}\" has errors, but will still work."
"themeHasErrors": "The currently active theme \"{theme}\" has errors, but will still work.",
"activateFailed": "Unable to activate the theme \"{theme}\"."
},
"redirects": {
"register": "Could not register custom redirects."