From 6f4075f38e34c215fff333e4983df9657e29cf06 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 22 Apr 2020 16:21:33 +0000 Subject: [PATCH] javascript: fix FileUploadError stacktraces When subclassing a JS error, most browsers include the constructor stacktrace :/ This is an issue, because: - The stacktrace is deeper than it should be - The stacktrace reaches into a polyfill for which there is not source map, which causes Sentry to infer the issue grouping from the JS file name. And the fingerprinted name changes on each release. So for each release, the stacktrace is different ; and Sentry can't group issues properly. --- .../shared/activestorage/file-upload-error.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/javascript/shared/activestorage/file-upload-error.js b/app/javascript/shared/activestorage/file-upload-error.js index 9b8b4285a..ef4aa5ded 100644 --- a/app/javascript/shared/activestorage/file-upload-error.js +++ b/app/javascript/shared/activestorage/file-upload-error.js @@ -20,9 +20,19 @@ export const FAILURE_CONNECTIVITY = 'file-upload-failure-connectivity'; export default class FileUploadError extends Error { constructor(message, status, code) { super(message); + this.name = 'FileUploadError'; this.status = status; this.code = code; + + // Prevent the constructor stacktrace from being included. + // (it messes up with Sentry issues grouping) + if (Error.captureStackTrace) { + // V8-only + Error.captureStackTrace(this, this.constructor); + } else { + this.stack = new Error().stack; + } } /**