Skip to content

Commit

Permalink
fix: Fix compiled-mode error formatting (#5623)
Browse files Browse the repository at this point in the history
We declare shaka.util.Error to extend the native Error, but only supplied a message field in uncompiled and debug modes.  This broke the Jasmine test framework when it tried to extract error message information from a compiled-mode shaka.util.Error object.

Now we always supply a message object, and merely skip the fancy enum formatting in compiled mode.
  • Loading branch information
joeyparrish committed Sep 8, 2023
1 parent e191c75 commit a19912e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ shaka.util.Error = class {
*/
this.handled = false;

// This improves the formatting of Errors in failure messages in the tests.
// A basic message for compiled mode.
let formattedMessage = 'Shaka Error ' + this.code;
if (goog.DEBUG) {
// This improves the formatting of Errors in failure messages in the
// tests in debug mode.
let categoryName = 'UNKNOWN';
let codeName = 'UNKNOWN';

Expand All @@ -79,17 +82,20 @@ shaka.util.Error = class {
}
}

/**
* A human-readable version of the category and code.
* <i>(Only available in uncompiled mode.)</i>
*
* @const {string}
* @exportDoc
*/
this.message = 'Shaka Error ' + categoryName + '.' + codeName +
' (' + this.data.toString() + ')';
formattedMessage = 'Shaka Error ' + categoryName + '.' + codeName +
' (' + this.data.toString() + ')';
}

/**
* In compiled mode, contains a basic message string with the error code.
* In uncompiled and debug modes, contains a human-readable version of the
* category and code as enums.
*
* @const {string}
* @exportDoc
*/
this.message = formattedMessage;

if (shaka.util.Error.createStack) {
try {
throw new Error(this.message || 'Shaka Error');
Expand Down

0 comments on commit a19912e

Please sign in to comment.