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,
}; };
const browser = Browser.from((await this._channel.launch(launchOptions)).browser); return await this._wrapApiCall(async () => {
browser._logger = logger; const browser = Browser.from((await this._channel.launch(launchOptions)).browser);
browser._setBrowserType(this); browser._logger = logger;
return browser; browser._setBrowserType(this);
return browser;
});
} }
private async _connectInsteadOfLaunching(): Promise<Browser> { private async _connectInsteadOfLaunching(): Promise<Browser> {
@ -119,13 +121,15 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
channel: options.channel, channel: options.channel,
userDataDir, userDataDir,
}; };
const result = await this._channel.launchPersistentContext(persistentParams); return await this._wrapApiCall(async () => {
const context = BrowserContext.from(result.context); const result = await this._channel.launchPersistentContext(persistentParams);
context._options = contextParams; const context = BrowserContext.from(result.context);
context._logger = logger; context._options = contextParams;
context._setBrowserType(this); context._logger = logger;
await this._onDidCreateContext?.(context); context._setBrowserType(this);
return context; await this._onDidCreateContext?.(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 : '';
e.message = apiName + ': ' + e.message; if (apiName && !apiName.includes('<anonymous>'))
e.stack = e.message + '\n' + frameTexts.join('\n') + innerError; 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); csi?.onApiCallEnd(callCookie, e);
logApiCall(logger, `<= ${apiName} failed`, isInternal); logApiCall(logger, `<= ${apiName} failed`, isInternal);
throw e; throw e;