/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
goog.provide('shaka.util.Error');
/**
* Creates a new Error.
*
* @param {shaka.util.Error.Severity} severity
* @param {shaka.util.Error.Category} category
* @param {shaka.util.Error.Code} code
* @param {...*} var_args
*
* @constructor
* @struct
* @export
* @extends {Error}
*/
shaka.util.Error = function(severity, category, code, var_args) {
this.severity = severity;
this.category = category;
this.code = code;
this.data = Array.prototype.slice.call(arguments, 3);
// This improves formatting of Errors in failure messages in the tests.
if (!COMPILED) {
var categoryName = 'UNKNOWN';
var codeName = 'UNKNOWN';
for (var k in shaka.util.Error.Category) {
if (shaka.util.Error.Category[k] == this.category)
categoryName = k;
}
for (var k in shaka.util.Error.Code) {
if (shaka.util.Error.Code[k] == this.code)
codeName = k;
}
/**
* A human-readable version of the category and code.
* (Only available in uncompiled mode.)
*
* @const {string}
* @exportDoc
*/
this.message = 'Shaka Error ' + categoryName + '.' + codeName +
' (' + this.data.toString() + ')';
try {
throw new Error(this.message);
} catch (e) {
/**
* A stack-trace showing where the error occurred.
* (Only available in uncompiled mode.)
*
* @const {string}
* @exportDoc
*/
this.stack = e.stack;
}
}
};
/**
* @type {shaka.util.Error.Severity}
* @expose
*/
shaka.util.Error.prototype.severity;
/**
* @const {shaka.util.Error.Category}
* @expose
*/
shaka.util.Error.prototype.category;
/**
* @const {shaka.util.Error.Code}
* @expose
*/
shaka.util.Error.prototype.code;
/**
* @const {!Array.<*>}
* @expose
*/
shaka.util.Error.prototype.data;
/**
* @return {string}
* @override
*/
shaka.util.Error.prototype.toString = function() {
return 'shaka.util.Error ' + JSON.stringify(this, null, ' ');
};
/**
* @enum {number}
* @export
*/
shaka.util.Error.Severity = {
/**
* An error occurred, but the Player is attempting to recover from the error.
*
* If the Player cannot ultimately recover, it still may not throw a CRITICAL
* error. For example, retrying for a media segment will never result in
* a CRITICAL error (the Player will just retry forever).
*/
'RECOVERABLE': 1,
/**
* A critical error that the library cannot recover from. These usually cause
* the Player to stop loading or updating. A new manifest must be loaded
* to reset the library.
*/
'CRITICAL': 2
};
/**
* @enum {number}
* @export
*/
shaka.util.Error.Category = {
/** Errors from the network stack. */
'NETWORK': 1,
/** Errors parsing text streams. */
'TEXT': 2,
/** Errors parsing or processing audio or video streams. */
'MEDIA': 3,
/** Errors parsing the Manifest. */
'MANIFEST': 4,
/** Errors related to streaming. */
'STREAMING': 5,
/** Errors related to DRM. */
'DRM': 6,
/** Miscellaneous errors from the player. */
'PLAYER': 7,
/** Errors related to cast. */
'CAST': 8,
/** Errors in the database storage (offline). */
'STORAGE': 9
};
/**
* @enum {number}
* @export
*/
shaka.util.Error.Code = {
/**
* A network request was made using an unsupported URI scheme.
*
error.data[0] is the URI.
*/
'UNSUPPORTED_SCHEME': 1000,
/**
* An HTTP network request returned an HTTP status that indicated a failure.
*
error.data[0] is the URI.
*
error.data[1] is the status code.
*
error.data[2] is the response text, or null if the response could not
* be interpretted as text.
*
error.data[3] is the map of response headers.
*/
'BAD_HTTP_STATUS': 1001,
/**
* An HTTP network request failed with an error, but not from the server.
*
error.data[0] is the URI.
*/
'HTTP_ERROR': 1002,
/**
* A network request timed out.
*
error.data[0] is the URI.
*/
'TIMEOUT': 1003,
/**
* A network request was made with a malformed data URI.
*
error.data[0] is the URI.
*/
'MALFORMED_DATA_URI': 1004,
/**
* A network request was made with a data URI using an unknown encoding.
*
error.data[0] is the URI.
*/
'UNKNOWN_DATA_URI_ENCODING': 1005,
/**
* A request filter threw an error.
*
error.data[0] is the original error.
*/
'REQUEST_FILTER_ERROR': 1006,
/**
* A response filter threw an error.
*
error.data[0] is the original error.
*/
'RESPONSE_FILTER_ERROR': 1007,
/** The text parser failed to parse a text stream due to an invalid header. */
'INVALID_TEXT_HEADER': 2000,
/** The text parser failed to parse a text stream due to an invalid cue. */
'INVALID_TEXT_CUE': 2001,
// RETIRED: 'INVALID_TEXT_SETTINGS': 2002,
/**
* Was unable to detect the encoding of the response text. Suggest adding
* byte-order-markings to the response data.
*/
'UNABLE_TO_DETECT_ENCODING': 2003,
/** The response data contains invalid Unicode character encoding. */
'BAD_ENCODING': 2004,
/**
* The XML parser failed to parse an xml stream, or the XML lacks mandatory
* elements for TTML.
*
error.data[0] is the URI associated with the XML.
*/
'INVALID_XML': 2005,
// RETIRED: 'INVALID_TTML': 2006,
/**
* MP4 segment does not contain TTML.
*/
'INVALID_MP4_TTML': 2007,
/**
* MP4 segment does not contain VTT.
*/
'INVALID_MP4_VTT': 2008,
/**
* Some component tried to read past the end of a buffer. The segment index,
* init segment, or PSSH may be malformed.
*/
'BUFFER_READ_OUT_OF_BOUNDS': 3000,
/**
* Some component tried to parse an integer that was too large to fit in a
* JavaScript number without rounding error. JavaScript can only natively
* represent integers up to 53 bits.
*/
'JS_INTEGER_OVERFLOW': 3001,
/**
* The EBML parser used to parse the WebM container encountered an integer,
* ID, or other field larger than the maximum supported by the parser.
*/
'EBML_OVERFLOW': 3002,
/**
* The EBML parser used to parse the WebM container encountered a floating-
* point field of a size not supported by the parser.
*/
'EBML_BAD_FLOATING_POINT_SIZE': 3003,
/**
* The MP4 SIDX parser found the wrong box type.
* Either the segment index range is incorrect or the data is corrupt.
*/
'MP4_SIDX_WRONG_BOX_TYPE': 3004,
/**
* The MP4 SIDX parser encountered an invalid timescale.
* The segment index data may be corrupt.
*/
'MP4_SIDX_INVALID_TIMESCALE': 3005,
/** The MP4 SIDX parser encountered a type of SIDX that is not supported. */
'MP4_SIDX_TYPE_NOT_SUPPORTED': 3006,
/**
* The WebM Cues parser was unable to locate the Cues element.
* The segment index data may be corrupt.
*/
'WEBM_CUES_ELEMENT_MISSING': 3007,
/**
* The WebM header parser was unable to locate the Ebml element.
* The init segment data may be corrupt.
*/
'WEBM_EBML_HEADER_ELEMENT_MISSING': 3008,
/**
* The WebM header parser was unable to locate the Segment element.
* The init segment data may be corrupt.
*/
'WEBM_SEGMENT_ELEMENT_MISSING': 3009,
/**
* The WebM header parser was unable to locate the Info element.
* The init segment data may be corrupt.
*/
'WEBM_INFO_ELEMENT_MISSING': 3010,
/**
* The WebM header parser was unable to locate the Duration element.
* The init segment data may be corrupt or may have been incorrectly encoded.
* Shaka requires a duration in WebM DASH content.
*/
'WEBM_DURATION_ELEMENT_MISSING': 3011,
/**
* The WebM Cues parser was unable to locate the Cue Track Positions element.
* The segment index data may be corrupt.
*/
'WEBM_CUE_TRACK_POSITIONS_ELEMENT_MISSING': 3012,
/**
* The WebM Cues parser was unable to locate the Cue Time element.
* The segment index data may be corrupt.
*/
'WEBM_CUE_TIME_ELEMENT_MISSING': 3013,
/**
* A MediaSource operation failed.
*
error.data[0] is a MediaError code from the video element.
*/
'MEDIA_SOURCE_OPERATION_FAILED': 3014,
/**
* A MediaSource operation threw an exception.
*
error.data[0] is the exception that was thrown.
*/
'MEDIA_SOURCE_OPERATION_THREW': 3015,
/**
* The video element reported an error.
*
error.data[0] is a MediaError code from the video element.
*
On Edge & IE, error.data[1] is a Microsoft extended error code in hex.
*/
'VIDEO_ERROR': 3016,
/**
* A MediaSource operation threw QuotaExceededError and recovery failed. The
* content cannot be played correctly because the segments are too large for
* the browser/platform. This may occur when attempting to play very high
* quality, very high bitrate content on low-end devices.
*
error.data[0] is the type of content which caused the error.
*/
'QUOTA_EXCEEDED_ERROR': 3017,
/**
* The Player was unable to guess the manifest type based on file extension
* or MIME type. To fix, try one of the following:
*