Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include stack trace in errors dispatched from production builds #5407

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions lib/util/error.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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