Skip to content

Commit

Permalink
feat: Include stack trace in errors dispatched from production builds (
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-atehortua committed Jul 19, 2023
1 parent f53349f commit 7d049eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
46 changes: 21 additions & 25 deletions lib/util/error.js
Expand Up @@ -88,20 +88,19 @@ shaka.util.Error = class {
*/
this.message = 'Shaka Error ' + categoryName + '.' + codeName +
' (' + this.data.toString() + ')';
}

if (shaka.util.Error.createStack) {
try {
throw new Error(this.message);
} catch (e) {
/**
* A stack-trace showing where the error occurred.
* <i>(Only available in uncompiled mode.)</i>
*
* @const {string}
* @exportDoc
*/
this.stack = e.stack;
}
if (shaka.util.Error.createStack) {
try {
throw new Error(this.message || 'Shaka Error');
} catch (e) {
/**
* A stack-trace showing where the error occurred.
*
* @const {string}
* @exportDoc
*/
this.stack = e.stack;
}
}
}
Expand All @@ -117,18 +116,15 @@ shaka.util.Error = class {
};


if (goog.DEBUG) {
/**
* If true, create a stack trace in Error objects.
*
* Only available in uncompiled mode, and disabled in tests to avoid issues
* with karma-jasmine. See comments in test/test/boot.js for details.
*
* @type {boolean}
*/
shaka.util.Error.createStack = true;
}

/**
* If true, create a stack trace in Error objects.
*
* Disabled in tests to avoid issues with karma-jasmine.
* See comments in test/test/boot.js for details.
*
* @type {boolean}
*/
shaka.util.Error.createStack = true;

/**
* @enum {number}
Expand Down
4 changes: 2 additions & 2 deletions test/test/boot.js
Expand Up @@ -357,8 +357,8 @@ function configureJasmineEnvironment() {
// Code in karma-jasmine's adapter will malform test failures when the
// expectation message contains a stack trace, losing the failure message and
// mixing up the stack trace of the failure. To avoid this, we modify
// shaka.util.Error not to create a stack trace. This trace is not available
// in production, and there is never any need for it in the tests.
// shaka.util.Error not to create a stack trace. There is never any need for
// this trace in the tests.
// Shimming shaka.util.Error proved too complicated because of a combination
// of compiler restrictions and ES6 language features, so this is by far the
// simpler answer.
Expand Down

0 comments on commit 7d049eb

Please sign in to comment.