Skip to content

Commit

Permalink
Have Walker Surface Error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vaage committed Mar 12, 2019
1 parent d78ea19 commit f9aaec4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 9 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions lib/routing/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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.Node>
* shaka.routing.Payload,
* !Error):!Promise.<shaka.routing.Node>
* }}
*
* @description
Expand All @@ -427,11 +429,13 @@ shaka.routing.Walker = class {
* payload.
*
* @property {function(
* shaka.routing.Payload):!Promise.<shaka.routing.Node> 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.<shaka.routing.Node> 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;

Expand Down

0 comments on commit f9aaec4

Please sign in to comment.