Skip to content

Commit

Permalink
chore: add missing await annotate floating promises
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Mar 12, 2021
1 parent 42e9a47 commit 45546e0
Show file tree
Hide file tree
Showing 35 changed files with 125 additions and 119 deletions.
3 changes: 2 additions & 1 deletion src/browserServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { BrowserContext, Video } from './server/browserContext';
import { StreamDispatcher } from './dispatchers/streamDispatcher';
import { ProtocolLogger } from './server/types';
import { CallMetadata, internalCallMetadata, SdkObject } from './server/instrumentation';
import { debugLogger } from './utils/debugLogger';

export class BrowserServerLauncherImpl implements BrowserServerLauncher {
private _browserType: BrowserType;
Expand Down Expand Up @@ -116,7 +117,7 @@ export class BrowserServerImpl extends EventEmitter implements BrowserServer {
socket.send(JSON.stringify(message));
};
socket.on('message', (message: string) => {
connection.dispatch(JSON.parse(Buffer.from(message).toString()));
connection.dispatch(JSON.parse(Buffer.from(message).toString())).catch(e => debugLogger.log('error', e));
});
socket.on('error', () => {});
const selectors = new Selectors();
Expand Down
19 changes: 12 additions & 7 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ program

commandWithOpenOptions('open [url]', 'open page in browser specified via -b, --browser', [])
.action(function(url, command) {
open(command, url, language());
open(command, url, language()).catch(logErrorAndExit);
})
.on('--help', function() {
console.log('');
Expand All @@ -53,7 +53,7 @@ commandWithOpenOptions('codegen [url]', 'open page and generate code for user ac
['-o, --output <file name>', 'saves the generated script to a file'],
['--target <language>', `language to use, one of javascript, python, python-async, csharp`, language()],
]).action(function(url, command) {
codegen(command, url, command.target, command.output);
codegen(command, url, command.target, command.output).catch(logErrorAndExit);
}).on('--help', function() {
console.log('');
console.log('Examples:');
Expand Down Expand Up @@ -105,7 +105,7 @@ const browsers = [
for (const {alias, name, type} of browsers) {
commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, [])
.action(function(url, command) {
open({ ...command, browser: type }, url, command.target);
open({ ...command, browser: type }, url, command.target).catch(logErrorAndExit);
}).on('--help', function() {
console.log('');
console.log('Examples:');
Expand All @@ -120,7 +120,7 @@ commandWithOpenOptions('screenshot <url> <filename>', 'capture a page screenshot
['--wait-for-timeout <timeout>', 'wait for timeout in milliseconds before taking a screenshot'],
['--full-page', 'whether to take a full page screenshot (entire scrollable area)'],
]).action(function(url, filename, command) {
screenshot(command, command, url, filename);
screenshot(command, command, url, filename).catch(logErrorAndExit);
}).on('--help', function() {
console.log('');
console.log('Examples:');
Expand All @@ -133,7 +133,7 @@ commandWithOpenOptions('pdf <url> <filename>', 'save page as pdf',
['--wait-for-selector <selector>', 'wait for given selector before saving as pdf'],
['--wait-for-timeout <timeout>', 'wait for given timeout in milliseconds before saving as pdf'],
]).action(function(url, filename, command) {
pdf(command, command, url, filename);
pdf(command, command, url, filename).catch(logErrorAndExit);
}).on('--help', function() {
console.log('');
console.log('Examples:');
Expand All @@ -146,7 +146,7 @@ if (process.env.PWTRACE) {
.command('show-trace [trace]')
.description('Show trace viewer')
.action(function(trace, command) {
showTraceViewer(trace);
showTraceViewer(trace).catch(logErrorAndExit);
}).on('--help', function() {
console.log('');
console.log('Examples:');
Expand All @@ -161,7 +161,7 @@ if (process.argv[2] === 'run-driver')
else if (process.argv[2] === 'print-api-json')
printApiJson();
else if (process.argv[2] === 'launch-server')
launchBrowserServer(process.argv[3], process.argv[4]);
launchBrowserServer(process.argv[3], process.argv[4]).catch(logErrorAndExit);
else
program.parse(process.argv);

Expand Down Expand Up @@ -424,6 +424,11 @@ function validateOptions(options: Options) {
}
}

function logErrorAndExit(e: Error) {
console.error(e);
process.exit(1);
}

function language(): string {
return process.env.PW_CLI_TARGET_LANG || 'javascript';
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Android extends ChannelOwner<channels.AndroidChannel, channels.Andr

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout });
void this._channel.setDefaultTimeoutNoReply({ timeout });
}

async devices(): Promise<AndroidDevice[]> {
Expand Down Expand Up @@ -90,7 +90,7 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout });
void this._channel.setDefaultTimeoutNoReply({ timeout });
}

serial(): string {
Expand Down
8 changes: 4 additions & 4 deletions src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
const func = this._bindings.get(bindingCall._initializer.name);
if (!func)
return;
bindingCall.call(func);
await bindingCall.call(func);
}

setDefaultNavigationTimeout(timeout: number) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
void this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
}

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout });
void this._channel.setDefaultTimeoutNoReply({ timeout });
}

browser(): Browser | null {
Expand Down Expand Up @@ -238,7 +238,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
});
}

async _onClose() {
_onClose() {
if (this._browser)
this._browser._contexts.delete(this);
this.emit(Events.BrowserContext.Close, this);
Expand Down
16 changes: 8 additions & 8 deletions src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
async _onBinding(bindingCall: BindingCall) {
const func = this._bindings.get(bindingCall._initializer.name);
if (func) {
bindingCall.call(func);
await bindingCall.call(func);
return;
}
this._browserContext._onBinding(bindingCall);
await this._browserContext._onBinding(bindingCall);
}

_onWorker(worker: Worker): void {
Expand Down Expand Up @@ -239,12 +239,12 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia

setDefaultNavigationTimeout(timeout: number) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
void this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
}

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout });
void this._channel.setDefaultTimeoutNoReply({ timeout });
}

video(): Video | null {
Expand Down Expand Up @@ -617,29 +617,29 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia

on(event: string | symbol, listener: Listener): this {
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: true });
this._channel.setFileChooserInterceptedNoReply({ intercepted: true }).catch(e => {});
super.on(event, listener);
return this;
}

addListener(event: string | symbol, listener: Listener): this {
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: true });
this._channel.setFileChooserInterceptedNoReply({ intercepted: true }).catch(e => {});
super.addListener(event, listener);
return this;
}

off(event: string | symbol, listener: Listener): this {
super.off(event, listener);
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: false });
this._channel.setFileChooserInterceptedNoReply({ intercepted: false }).catch(e => {});
return this;
}

removeListener(event: string | symbol, listener: Listener): this {
super.removeListener(event, listener);
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: false });
this._channel.setFileChooserInterceptedNoReply({ intercepted: false }).catch(e => {});
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dispatchers/browserContextDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
await this._context._setRequestInterceptor(undefined);
return;
}
this._context._setRequestInterceptor((route, request) => {
await this._context._setRequestInterceptor((route, request) => {
this._dispatchEvent('route', { route: new RouteDispatcher(this._scope, route), request: RequestDispatcher.from(this._scope, request) });
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/dispatchers/pageDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageInitializer> i
await this._page._setClientRequestInterceptor(undefined);
return;
}
this._page._setClientRequestInterceptor((route, request) => {
await this._page._setClientRequestInterceptor((route, request) => {
this._dispatchEvent('route', { route: new RouteDispatcher(this._scope, route), request: RequestDispatcher.from(this._scope, request) });
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/remote/playwrightServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export class PlaywrightServer {
ws.on('message', message => dispatcherConnection.dispatch(JSON.parse(message.toString())));
ws.on('close', () => {
debugLog('Client closed');
this._onDisconnect();
this._onDisconnect().catch(debugLog);
});
ws.on('error', error => {
debugLog('Client error ' + error);
this._onDisconnect();
this._onDisconnect().catch(debugLog);
});
dispatcherConnection.onmessage = message => ws.send(JSON.stringify(message));
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), createPlaywright());
Expand Down
2 changes: 1 addition & 1 deletion src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class AndroidDevice extends SdkObject {
await this.installApk(await readFileAsync(require.resolve(`../../../bin/${file}`)));

debug('pw:android')('Starting the new driver');
this.shell('am instrument -w com.microsoft.playwright.androiddriver.test/androidx.test.runner.AndroidJUnitRunner');
this.shell('am instrument -w com.microsoft.playwright.androiddriver.test/androidx.test.runner.AndroidJUnitRunner').catch(e => debug('pw:android')(e));
const socket = await this._waitForLocalAbstract('playwright_android_driver_socket');
const transport = new Transport(socket, socket, socket, 'be');
transport.onmessage = message => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/android/backendAdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BufferedSocketWrapper extends EventEmitter implements SocketBackend {
this._isClosed = true;
if (this._notifyReader)
this._notifyReader();
this.close();
void this.close();
this.emit('close');
});
this._socket.on('error', error => this.emit('error', error));
Expand Down
6 changes: 3 additions & 3 deletions src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export abstract class Browser extends SdkObject {
const download = this._downloads.get(uuid);
if (!download)
return;
download._reportFinished(error);
download._reportFinished(error).catch(e => {});
this._downloads.delete(uuid);
}

_videoStarted(context: BrowserContext, videoId: string, path: string, pageOrError: Promise<Page | Error>) {
const video = new Video(context, videoId, path);
this._idToVideo.set(videoId, video);
context.emit(BrowserContext.Events.VideoStarted, video);
pageOrError.then(pageOrError => {
void pageOrError.then(pageOrError => {
if (pageOrError instanceof Page)
pageOrError.videoStarted(video);
});
Expand All @@ -105,7 +105,7 @@ export abstract class Browser extends SdkObject {
_videoFinished(videoId: string) {
const video = this._idToVideo.get(videoId)!;
this._idToVideo.delete(videoId);
video._finish();
void video._finish();
}

_didClose() {
Expand Down
11 changes: 6 additions & 5 deletions src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { readProtocolStream } from './crProtocolHelper';
import { Protocol } from './protocol';
import { CRExecutionContext } from './crExecutionContext';
import { CRDevTools } from './crDevTools';
import { debugLogger } from '../../utils/debugLogger';

export class CRBrowser extends Browser {
readonly _connection: CRConnection;
Expand Down Expand Up @@ -135,15 +136,15 @@ export class CRBrowser extends Browser {
}

if (targetInfo.type === 'other' && targetInfo.url.startsWith('devtools://devtools') && this._devtools) {
this._devtools.install(session);
this._devtools.install(session).catch(e => debugLogger.log('error', e));
return;
}

if (targetInfo.type === 'other' || !context) {
if (waitingForDebugger) {
// Ideally, detaching should resume any target, but there is a bug in the backend.
session._sendMayFail('Runtime.runIfWaitingForDebugger').then(() => {
this._session._sendMayFail('Target.detachFromTarget', { sessionId });
void session._sendMayFail('Runtime.runIfWaitingForDebugger').then(() => {
return this._session._sendMayFail('Target.detachFromTarget', { sessionId });
});
}
return;
Expand All @@ -156,7 +157,7 @@ export class CRBrowser extends Browser {
if (targetInfo.type === 'background_page') {
const backgroundPage = new CRPage(session, targetInfo.targetId, context, null, false);
this._backgroundPages.set(targetInfo.targetId, backgroundPage);
backgroundPage.pageOrError().then(pageOrError => {
void backgroundPage.pageOrError().then(pageOrError => {
if (pageOrError instanceof Page)
context!.emit(CRBrowserContext.CREvents.BackgroundPage, backgroundPage._page);
});
Expand All @@ -167,7 +168,7 @@ export class CRBrowser extends Browser {
const opener = targetInfo.openerId ? this._crPages.get(targetInfo.openerId) || null : null;
const crPage = new CRPage(session, targetInfo.targetId, context, opener, true);
this._crPages.set(targetInfo.targetId, crPage);
crPage._page.reportAsNew();
void crPage._page.reportAsNew();
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/chromium/crConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class CRConnection extends EventEmitter {
for (const session of this._sessions.values())
session._onClosed(browserDisconnectedLogs);
this._sessions.clear();
Promise.resolve().then(() => this.emit(ConnectionEvents.Disconnected));
void Promise.resolve().then(() => this.emit(ConnectionEvents.Disconnected));
}

close() {
Expand Down Expand Up @@ -187,7 +187,7 @@ export class CRSession extends EventEmitter {
callback.resolve(object.result);
} else {
assert(!object.id);
Promise.resolve().then(() => {
void Promise.resolve().then(() => {
if (this._eventListener)
this._eventListener(object.method!, object.params);
this.emit(object.method!, object.params);
Expand All @@ -211,7 +211,7 @@ export class CRSession extends EventEmitter {
callback.reject(rewriteErrorMessage(callback.error, `Protocol error (${callback.method}): ` + errorMessage));
this._callbacks.clear();
this._connection = null;
Promise.resolve().then(() => this.emit(CRSessionEvents.Disconnected));
void Promise.resolve().then(() => this.emit(CRSessionEvents.Disconnected));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/chromium/crCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class JSCoverage {
}

_onDebuggerPaused() {
this._client.send('Debugger.resume');
this._client.send('Debugger.resume').catch(() => {});
}

_onExecutionContextsCleared() {
Expand Down
Loading

0 comments on commit 45546e0

Please sign in to comment.