Skip to content

Commit

Permalink
handle async sendCommand rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Sep 24, 2016
1 parent 30ff4ec commit 026478b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/gather/drivers/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CriDriver extends Driver {
*/
sendCommand(command, params) {
if (this._cri === null) {
throw new Error('connect() must be called before attempting to send a command.');
return Promise.reject('connect() must be called before attempting to send a command.');
}

return new Promise((resolve, reject) => {
Expand Down
24 changes: 11 additions & 13 deletions lighthouse-core/gather/drivers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Driver {
this.sendCommand('Runtime.evaluate', {
expression,
includeCommandLineAPI: true
});
}).catch(reject);

// If this gets to 60s and it hasn't been resolved, reject the Promise.
asyncTimeout = setTimeout(
Expand All @@ -194,22 +194,22 @@ class Driver {
getSecurityState() {
return new Promise((resolve, reject) => {
this.once('Security.securityStateChanged', data => {
this.sendCommand('Security.disable');
resolve(data);
this.sendCommand('Security.disable')
.then(_ => resolve(data), reject);
});

this.sendCommand('Security.enable');
this.sendCommand('Security.enable').catch(reject);
});
}

getServiceWorkerVersions() {
return new Promise((resolve, reject) => {
this.once('ServiceWorker.workerVersionUpdated', data => {
this.sendCommand('ServiceWorker.disable');
resolve(data);
this.sendCommand('ServiceWorker.disable')
.then(_ => resolve(data), reject);
});

this.sendCommand('ServiceWorker.enable');
this.sendCommand('ServiceWorker.enable').catch(reject);
});
}

Expand Down Expand Up @@ -315,11 +315,11 @@ class Driver {
// When the tracing has ended this will fire with a stream handle.
this.once('Tracing.tracingComplete', streamHandle => {
this._readTraceFromStream(streamHandle)
.then(traceContents => resolve(traceContents));
.then(traceContents => resolve(traceContents), reject);
});

// Issue the command to stop tracing.
this.sendCommand('Tracing.end');
this.sendCommand('Tracing.end').catch(reject);
});
}

Expand Down Expand Up @@ -350,7 +350,7 @@ class Driver {
return this.sendCommand('IO.read', readArguments).then(onChunkRead);
};

this.sendCommand('IO.read', readArguments).then(onChunkRead);
this.sendCommand('IO.read', readArguments).then(onChunkRead).catch(reject);
});
}

Expand All @@ -368,9 +368,7 @@ class Driver {
this.on('Network.loadingFailed', this._networkRecorder.onLoadingFailed);
this.on('Network.resourceChangedPriority', this._networkRecorder.onResourceChangedPriority);

this.sendCommand('Network.enable').then(_ => {
resolve();
});
this.sendCommand('Network.enable').then(resolve, reject);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/gatherers/dobetterweb/websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class WebSQL extends Gatherer {
return new Promise((resolve, reject) => {
driver.once('Database.addDatabase', db => {
clearTimeout(timeout);
driver.sendCommand('Database.disable').then(_ => resolve(db));
driver.sendCommand('Database.disable').then(_ => resolve(db), reject);
});

driver.sendCommand('Database.enable');
driver.sendCommand('Database.enable').catch(reject);

// Wait for a websql db to be opened. Reject the Promise no dbs were created.
// TODO(ericbidelman): this assumes dbs are opened on page load.
Expand Down

0 comments on commit 026478b

Please sign in to comment.