Skip to content

A platform for community discussion. Free, open, simple.

DEV: Catch errors in theme/plugin onPageChange handlers (#24784)

David Taylorefbe5b7dda70
diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index dff4364e707..880be3fdc22 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -799,7 +799,8 @@ class PluginApi {
```
**/
onPageChange(fn) {
- this.onAppEvent("page:changed", (data) => fn(data.url, data.title));
+ const callback = wrapWithErrorHandler(fn, "broken_page_change_alert");
+ this.onAppEvent("page:changed", (data) => callback(data.url, data.title));
}
/**
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c9a46f4cf90..3c353a55eab 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -220,6 +220,7 @@ en:
only_admins: "(this message is only shown to site administrators)"
broken_decorator_alert: "Posts may not display correctly because one of the post content decorators on your site raised an error."
+ broken_page_change_alert: "An onPageChange handler raised an error. Check the browser developer tools for more information."
broken_plugin_alert: "Caused by plugin '%{name}'"