From 67a245129f53d99cce89aff3ea194b1098d65ee6 Mon Sep 17 00:00:00 2001 From: Tiago Lopes Date: Sat, 28 Jan 2023 00:30:21 +0000 Subject: [PATCH] feat(logs): Add extra logging for 3015 errors (#4932) This adds extra context to 3015 (MEDIA_SOURCE_OPERATION_THREW) errors, by attaching the error on the media element. This is helpful because, in some situations, media source operations can have very unhelpful exception strings like: `Error: Failed to execute 'appendBuffer' on 'SourceBuffer': The HTMLMediaElement.error attribute is not null` --- lib/media/media_source_engine.js | 6 ++++-- lib/util/error.js | 1 + test/media/media_source_engine_unit.js | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 6b607c4d1c..81bb8fafe2 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -1265,7 +1265,8 @@ shaka.media.MediaSourceEngine = class { shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_THREW, - exception); + exception, + this.video_.error || 'No error in the media element'); } finally { // Unblock the queues. for (const contentType in this.sourceBuffers_) { @@ -1308,7 +1309,8 @@ shaka.media.MediaSourceEngine = class { shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_THREW, - exception)); + exception, + this.video_.error || 'No error in the media element')); } this.popFromQueue_(contentType); } diff --git a/lib/util/error.js b/lib/util/error.js index 243f5ab156..a544689b59 100644 --- a/lib/util/error.js +++ b/lib/util/error.js @@ -462,6 +462,7 @@ shaka.util.Error.Code = { /** * A MediaSource operation threw an exception. *
error.data[0] is the exception that was thrown. + *
error.data[1] is the error object from the video element. */ 'MEDIA_SOURCE_OPERATION_THREW': 3015, diff --git a/test/media/media_source_engine_unit.js b/test/media/media_source_engine_unit.js index 3082cd5370..4806977212 100644 --- a/test/media/media_source_engine_unit.js +++ b/test/media/media_source_engine_unit.js @@ -374,12 +374,13 @@ describe('MediaSourceEngine', () => { it('rejects promise when operation throws', async () => { audioSourceBuffer.appendBuffer.and.throwError('fail!'); - mockVideo.error = {code: 5}; + mockVideo.error = {code: 5, message: 'something failed'}; const expected = Util.jasmineError(new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_THREW, - jasmine.objectContaining({message: 'fail!'}))); + jasmine.objectContaining({message: 'fail!'}), + {code: 5, message: 'something failed'})); await expectAsync( mediaSourceEngine.appendBuffer( ContentType.AUDIO, buffer, null, @@ -712,7 +713,8 @@ describe('MediaSourceEngine', () => { shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.MEDIA, shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_THREW, - jasmine.objectContaining({message: 'fail!'}))); + jasmine.objectContaining({message: 'fail!'}), + {code: 5})); await expectAsync(mediaSourceEngine.remove(ContentType.AUDIO, 1, 5)) .toBeRejectedWith(expected); expect(audioSourceBuffer.remove).toHaveBeenCalledWith(1, 5);