chore: beautify error message (#18002)

This commit is contained in:
Pavel Feldman 2022-10-18 14:16:47 -04:00 committed by GitHub
parent 8ff2eda16a
commit 64e80f0460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View file

@ -81,10 +81,12 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs), ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
env: options.env ? envObjectToArray(options.env) : undefined, env: options.env ? envObjectToArray(options.env) : undefined,
}; };
return await this._wrapApiCall(async () => {
const browser = Browser.from((await this._channel.launch(launchOptions)).browser); const browser = Browser.from((await this._channel.launch(launchOptions)).browser);
browser._logger = logger; browser._logger = logger;
browser._setBrowserType(this); browser._setBrowserType(this);
return browser; return browser;
});
} }
private async _connectInsteadOfLaunching(): Promise<Browser> { private async _connectInsteadOfLaunching(): Promise<Browser> {
@ -119,6 +121,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
channel: options.channel, channel: options.channel,
userDataDir, userDataDir,
}; };
return await this._wrapApiCall(async () => {
const result = await this._channel.launchPersistentContext(persistentParams); const result = await this._channel.launchPersistentContext(persistentParams);
const context = BrowserContext.from(result.context); const context = BrowserContext.from(result.context);
context._options = contextParams; context._options = contextParams;
@ -126,6 +129,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
context._setBrowserType(this); context._setBrowserType(this);
await this._onDidCreateContext?.(context); await this._onDidCreateContext?.(context);
return context; return context;
});
} }
connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>; connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>;

View file

@ -132,8 +132,13 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
return result; return result;
} catch (e) { } catch (e) {
const innerError = ((process.env.PWDEBUGIMPL || isUnderTest()) && e.stack) ? '\n<inner error>\n' + e.stack : ''; const innerError = ((process.env.PWDEBUGIMPL || isUnderTest()) && e.stack) ? '\n<inner error>\n' + e.stack : '';
if (apiName && !apiName.includes('<anonymous>'))
e.message = apiName + ': ' + e.message; e.message = apiName + ': ' + e.message;
e.stack = e.message + '\n' + frameTexts.join('\n') + innerError; const stackFrames = '\n' + frameTexts.join('\n') + innerError;
if (stackFrames.trim())
e.stack = e.message + stackFrames;
else
e.stack = '';
csi?.onApiCallEnd(callCookie, e); csi?.onApiCallEnd(callCookie, e);
logApiCall(logger, `<= ${apiName} failed`, isInternal); logApiCall(logger, `<= ${apiName} failed`, isInternal);
throw e; throw e;