Skip to content

Commit

Permalink
feat(logs): Add extra logging for 3015 errors (#4932)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
PsychoSnake authored Jan 28, 2023
1 parent d465942 commit 67a2451
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ shaka.util.Error.Code = {
/**
* A MediaSource operation threw an exception.
* <br> error.data[0] is the exception that was thrown.
* <br> error.data[1] is the error object from the video element.
*/
'MEDIA_SOURCE_OPERATION_THREW': 3015,

Expand Down
8 changes: 5 additions & 3 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 67a2451

Please sign in to comment.