FEATURE: detect theme errors and catch them (#7589)

* FEATURE: detect theme errors and catch them

* Bump COMPILER_VERSION

* Feedback

* Override eslint no console for one line

* Can't use our ajax method

* remove emoji from translation file
This commit is contained in:
Osama Sayegh
2019-05-24 17:25:55 +03:00
committed by GitHub
parent a51e2271af
commit e20c30987c
7 changed files with 97 additions and 6 deletions

View File

@@ -660,5 +660,39 @@ export function postRNWebviewMessage(prop, value) {
}
}
function reportToLogster(name, error) {
const data = {
message: `${name} theme/component is throwing errors`,
stacktrace: error.stack
};
Ember.$.ajax(`${Discourse.BaseUri}/logs/report_js_error`, {
data,
type: "POST",
cache: false
});
}
// this function is used in lib/theme_javascript_compiler.rb
export function rescueThemeError(name, error, api) {
/* eslint-disable-next-line no-console */
console.error(`"${name}" error:`, error);
reportToLogster(name, error);
const currentUser = api.getCurrentUser();
if (!currentUser || !currentUser.admin) {
return;
}
const path = `${Discourse.BaseUri}/admin/customize/themes`;
const message = I18n.t("themes.broken_theme_alert", {
theme: name,
path: `<a href="${path}">${path}</a>`
});
const alertDiv = document.createElement("div");
alertDiv.classList.add("broken-theme-alert");
alertDiv.innerHTML = `⚠️ ${message}`;
document.body.prepend(alertDiv);
}
// This prevents a mini racer crash
export default {};