Global errors handling and reporting

Just curious who is using what for errors tracking and global errors handling? Does XD store provide any such functionality? I made attempt to use bugsnag but plugin crashes on start.

1 Like

I put try catch around problem areas but no tracking. I came across trackjs today. I haven’t tried if it and don’t know if will work in UXP or not.

If you are on a budget you could always write your own logging in your catch block post the error to a page on your server.

try {
   // try or try not there is no do
catch (e) {

function logError(e) {
    // post error to your site

Note: You might have to disclose if you post data back to your site.

Also, it looks like there is something called Sentry.

You can capture global errors using the window.onerror event:

But it’s not clear if that is supported in UXP.

I’ve tried the following and there were no results:

function errorHandler (msg, url, lineNo, columnNo, error) {
	var string = msg.toLowerCase();
	var substring = "script error";

	if (string.indexOf(substring) > -1){
	  log('Script Error: See Browser Console for Detail');
	} else {
	  var message = [
		 'Message: ' + msg,
		 'URL: ' + url,
		 'Line: ' + lineNo,
		 'Column: ' + columnNo,
		 'Error object: ' + JSON.stringify(error)
	  ].join(' - ');
	return false;

function errorHandler2 (error) {
	return false;

// trying to catch the errors:
window.addEventListener("error", errorHandler2);
window.addEventListener("error", errorHandler2, true);
window.onerror = errorHandler;
GlobalEventHandlers.onerror = errorHandler;

If I got it right window object is an empty object with mocked functions so addEventListener just doesn’t do anything, correct me if I’m wrong.
try…catch doesn’t make much sense as they catch mostly expected exceptions.
Also I slightly don’t follow how it will work in general. All plugins (panels and dialogs) exist in the same window object so if someone write in dialog window.onerror = errorHandler; it will overwrite handler for current active panel.

window.onerror = errorHandler;

is how they suggest to do it in the browser. Well one of a few methods. Yes, that way would overwrite an existing global error handler. UXP probably has one already and it’s what is showing in the Developer console. If this was in production I would add an event listener.

I don’t know that they are the same window object. My plugin can’t get errors from other plugins or vice versa.

I’ve changed this to a feature request. Let me know and I can create another post.

For me, it would be great to be able to listen for global uncaught errors for my own case and to prevent them from being shown in the developer console.

The first reason to prevent them from showing them in the console is because in the past text areas with a lot of information can slow down the entire application. Maybe it’s different but I’ve seen this in IDEs and in browsers.

The second reason to prevent showing errors in the console is because the user will never see these messages.

Instead if an error happens an error icon can be shown to inform the user to reload the plugin (in my case).

This would be very helpful because it would allow us to use Sentry and track the errors that our customers are having.

1 Like