From 64e80f0460d1f4d000d5f9ed7018ea0a8c329a77 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 18 Oct 2022 14:16:47 -0400 Subject: [PATCH] chore: beautify error message (#18002) --- .../playwright-core/src/client/browserType.ts | 26 +++++++++++-------- .../src/client/channelOwner.ts | 9 +++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index 89254e55a1..7b02456c4d 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -81,10 +81,12 @@ export class BrowserType extends ChannelOwner imple ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs), env: options.env ? envObjectToArray(options.env) : undefined, }; - const browser = Browser.from((await this._channel.launch(launchOptions)).browser); - browser._logger = logger; - browser._setBrowserType(this); - return browser; + return await this._wrapApiCall(async () => { + const browser = Browser.from((await this._channel.launch(launchOptions)).browser); + browser._logger = logger; + browser._setBrowserType(this); + return browser; + }); } private async _connectInsteadOfLaunching(): Promise { @@ -119,13 +121,15 @@ export class BrowserType extends ChannelOwner imple channel: options.channel, userDataDir, }; - const result = await this._channel.launchPersistentContext(persistentParams); - const context = BrowserContext.from(result.context); - context._options = contextParams; - context._logger = logger; - context._setBrowserType(this); - await this._onDidCreateContext?.(context); - return context; + return await this._wrapApiCall(async () => { + const result = await this._channel.launchPersistentContext(persistentParams); + const context = BrowserContext.from(result.context); + context._options = contextParams; + context._logger = logger; + context._setBrowserType(this); + await this._onDidCreateContext?.(context); + return context; + }); } connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise; diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index d679595f0d..c2ebf7ada8 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -132,8 +132,13 @@ export abstract class ChannelOwner\n' + e.stack : ''; - e.message = apiName + ': ' + e.message; - e.stack = e.message + '\n' + frameTexts.join('\n') + innerError; + if (apiName && !apiName.includes('')) + e.message = apiName + ': ' + e.message; + const stackFrames = '\n' + frameTexts.join('\n') + innerError; + if (stackFrames.trim()) + e.stack = e.message + stackFrames; + else + e.stack = ''; csi?.onApiCallEnd(callCookie, e); logApiCall(logger, `<= ${apiName} failed`, isInternal); throw e;