Skip to content

Commit

Permalink
URIEncode stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Mar 8, 2024
1 parent 425c310 commit 4c6259f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
32 changes: 16 additions & 16 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ let LABELS = [], DELETE_HISTORY = [];
const originalWarn = console.warn;
const originalError = console.error;

function customURLEncode(str) {
return encodeURIComponent(str)
.replace(/[!'()*]/g, (c) => {
// Replacing additional characters manually
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
})
.replace(/%20/g, '+'); // Optionally replace space with '+' instead of '%20'
}

// Override console.warn to intercept and track warnings
console.warn = function(message) {
// Call the original console.warn to maintain default behavior
originalWarn.apply(console, arguments);

// Track the warning message using your tracking function
track('Warnings', arguments[0], arguments[1]);
track('Warnings', arguments[0], encodeURIComponent(arguments[1]));
};

// Override console.error to intercept and track errors
Expand All @@ -23,23 +32,17 @@ console.error = function(message) {
originalError.apply(console, arguments);

// Track the error message using your tracking function
track('Errors', arguments[0], arguments[1]);
};
// Implement error handling in the worker
window.onerror = function (message) {
//split the message back to message & stack
const [msg, stack] = message.split('|')
// Send an error message
track('Unhandled UI Error', msg, stack);
track('Errors', arguments[0], encodeURIComponent(arguments[1]));
};


window.addEventListener('unhandledrejection', function(event) {
// Extract the error message and stack trace from the event
const errorMessage = event.reason.message;
const stackTrace = event.reason.stack;

// Track the unhandled promise rejection
track('Unhandled UI Promise Rejection', errorMessage, stackTrace);
track('Unhandled UI Promise Rejection', errorMessage, encodeURIComponent(stackTrace));
});

window.addEventListener('rejectionhandled', function(event) {
Expand All @@ -48,7 +51,7 @@ window.addEventListener('rejectionhandled', function(event) {
const stackTrace = event.reason.stack;

// Track the unhandled promise rejection
track('Handled UI Promise Rejection', errorMessage, stackTrace);
track('Handled UI Promise Rejection', errorMessage, encodeURIComponent(stackTrace));
});

const STATE = {
Expand Down Expand Up @@ -1465,10 +1468,8 @@ window.onload = async () => {

// Attach an error event listener to the window object
window.onerror = function(message, file, lineno, colno, error) {
const source = `${file}:${lineno}:${colno}`;

track('Error', message, source);
// Return false not to inhibit the default browser error handling
track('Error', error.message, encodeURIComponent(error.stack));
// Return false not to inhibit the default error handling
return false;
};
//fill in defaults - after updates add new items
Expand Down Expand Up @@ -1635,7 +1636,6 @@ window.onload = async () => {
.catch(error => console.log('Error posting tracking:', error))
}
})
adjustSpecDims(true)
}


Expand Down
19 changes: 9 additions & 10 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ console.warn = function(message) {
originalWarn.apply(console, arguments);

// Track the warning message using your tracking function
track('Warnings', arguments[0], arguments[1]);
track('Warnings', arguments[0], encodeURIComponent(arguments[1]));
};

// Override console.error to intercept and track errors
Expand All @@ -38,23 +38,22 @@ console.error = function(message) {
originalError.apply(console, arguments);

// Track the error message using your tracking function
track('Handled Errors', arguments[0], arguments[1]);
track('Handled Errors', arguments[0], encodeURIComponent(arguments[1]));
};
// Implement error handling in the worker
self.onerror = function (message) {
//split the message back to message & stack
const [msg, stack] = message.split('|')
// Send an error message
track('Unhandled Worker Errors', msg, stack);
};
self.onerror = function(message, file, lineno, colno, error) {
track('Unhandled Worker Error', error.message, encodeURIComponent(error.stack));
// Return false not to inhibit the default error handling
return false;
};

self.addEventListener('unhandledrejection', function(event) {
// Extract the error message and stack trace from the event
const errorMessage = event.reason.message;
const stackTrace = event.reason.stack;

// Track the unhandled promise rejection
track('Unhandled Worker Promise Rejections', errorMessage, stackTrace);
track('Unhandled Worker Promise Rejections', errorMessage, encodeURIComponent(stackTrace));
});

self.addEventListener('rejectionhandled', function(event) {
Expand All @@ -63,7 +62,7 @@ self.addEventListener('rejectionhandled', function(event) {
const stackTrace = event.reason.stack;

// Track the unhandled promise rejection
track('Handled Worker Promise Rejections', errorMessage, stackTrace);
track('Handled Worker Promise Rejections', errorMessage, encodeURIComponent(stackTrace));
});

//Object will hold files in the diskDB, and the active timestamp from the most recent selection analysis.
Expand Down

0 comments on commit 4c6259f

Please sign in to comment.