From f9aaec4d2a63bf12bd6016cbaa5fc7873aa13b69 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Wed, 6 Mar 2019 02:47:42 +0000 Subject: [PATCH] Have Walker Surface Error When the walker encounters an error, it handles the error but it did not surface the error. This made it hard to log the error without putting the log statement in the walker. This changes the walker to pass the error to the handle error method so that the class using the player (e.g. Player) can use the error in determining how to respond to the error. Change-Id: Ied91f8fcf80d5dd8058e8ba58de16d25213c2f0b --- lib/player.js | 10 +++++++++- lib/routing/walker.js | 18 +++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/player.js b/lib/player.js index 4957b7a9e3..8535a2aa02 100644 --- a/lib/player.js +++ b/lib/player.js @@ -269,7 +269,15 @@ shaka.Player = function(mediaElement, dependencyInjector) { const action = actions.get(node); return action(has, wants); }, - handleError: async (has) => { + handleError: async (has, error) => { + shaka.log.warning('The walker saw an error:'); + if (error instanceof shaka.util.Error) { + shaka.log.warning('Error Code:', error.code); + } else { + shaka.log.warning('Error Message:', error.message); + shaka.log.warning('Error Stack:', error.stack); + } + // TODO(vaage): We don't always need to return to detached. If we have a // video element we may want to return to attached. We should // have this so that we return to |attachNode| when diff --git a/lib/routing/walker.js b/lib/routing/walker.js index aa005dcc2c..2b5b8d26c1 100644 --- a/lib/routing/walker.js +++ b/lib/routing/walker.js @@ -370,7 +370,8 @@ shaka.routing.Walker = class { // Still need to handle error because aborting an operation could leave us // in an unexpected state. this.currentlyAt_ = await this.implementation_.handleError( - this.currentlyWith_); + this.currentlyWith_, + error); } } @@ -400,7 +401,8 @@ shaka.routing.Walker = class { * shaka.routing.Payload, * shaka.routing.Payload):!shaka.util.AbortableOperation, * handleError: function( - * shaka.routing.Payload):!Promise. + * shaka.routing.Payload, + * !Error):!Promise. * }} * * @description @@ -427,11 +429,13 @@ shaka.routing.Walker = class { * payload. * * @property {function( - * shaka.routing.Payload):!Promise. handleError - * When |enterNode| throws an error or is aborted, this will be called. This - * allows the walker to reset to a usable state. This method will be passed - * the current payload and will return the node that the walker starts at. - * This method may modify the current payload. + * shaka.routing.Payload, + * !Error):!Promise. handleError + * This is the callback for when |enterNode| fails. It is passed the current + * payload and the error. If a step is aborted, the error will be + * OPERATION_ABORTED. It should reset all external dependences, modify the + * payload, and return the new current node. Calls to |handleError| should + * always resolve and the walker should always be able to continue operating. */ shaka.routing.Walker.Implementation;