From b3bfdd2024097be1974e28b3766419189b4a9fe0 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:15:20 +0100 Subject: [PATCH] refactor!: remove `error` const, change CustomError to PuppeteerError (#11777) Co-authored-by: Alex Rudenko Co-authored-by: Alex Rudenko --- docs/api/index.md | 4 +- docs/api/puppeteer.errors.md | 33 ------------ docs/api/puppeteer.protocolerror.md | 4 +- ...omerror.md => puppeteer.puppeteererror.md} | 12 ++--- docs/api/puppeteer.puppeteererrors.md | 22 -------- docs/api/puppeteer.timeouterror.md | 4 +- docs/api/puppeteer.unsupportedoperation.md | 4 +- packages/puppeteer-core/src/common/Errors.ts | 50 ++----------------- 8 files changed, 17 insertions(+), 116 deletions(-) delete mode 100644 docs/api/puppeteer.errors.md rename docs/api/{puppeteer.customerror.md => puppeteer.puppeteererror.md} (51%) delete mode 100644 docs/api/puppeteer.puppeteererrors.md diff --git a/docs/api/index.md b/docs/api/index.md index 72893f5f1a6..c4d86c21c57 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -16,7 +16,6 @@ sidebar_label: API | [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. | | [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gather information about parts of JavaScript and CSS that were used by the page. | | [CSSCoverage](./puppeteer.csscoverage.md) | | -| [CustomError](./puppeteer.customerror.md) | | | [DeviceRequestPrompt](./puppeteer.devicerequestprompt.md) | Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth. | | [DeviceRequestPromptDevice](./puppeteer.devicerequestpromptdevice.md) | Device in a request prompt. | | [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the dialog event. | @@ -35,6 +34,7 @@ sidebar_label: API | [ProductLauncher](./puppeteer.productlauncher.md) | Describes a launcher - a class that is able to create and launch a browser instance. | | [ProtocolError](./puppeteer.protocolerror.md) | ProtocolError is emitted whenever there is an error from the protocol. | | [Puppeteer](./puppeteer.puppeteer.md) |

The main Puppeteer class.

IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require puppeteer. That class extends Puppeteer, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).

| +| [PuppeteerError](./puppeteer.puppeteererror.md) | The base class for all Puppeteer-specific errors | | [PuppeteerNode](./puppeteer.puppeteernode.md) |

Extends the main [Puppeteer](./puppeteer.puppeteer.md) class with Node specific behaviour for fetching and downloading browsers.

If you're using Puppeteer in a Node environment, this is the class you'll get when you run require('puppeteer') (or the equivalent ES import).

| | [ScreenRecorder](./puppeteer.screenrecorder.md) | | | [SecurityDetails](./puppeteer.securitydetails.md) | The SecurityDetails class represents the security details of a response that was received over a secure connection. | @@ -127,7 +127,6 @@ sidebar_label: API | [PDFMargin](./puppeteer.pdfmargin.md) | | | [PDFOptions](./puppeteer.pdfoptions.md) | Valid options to configure PDF generation via [Page.pdf()](./puppeteer.page.pdf.md). | | [Point](./puppeteer.point.md) | | -| [PuppeteerErrors](./puppeteer.puppeteererrors.md) | | | [PuppeteerLaunchOptions](./puppeteer.puppeteerlaunchoptions.md) | | | [RemoteAddress](./puppeteer.remoteaddress.md) | | | [ResponseForRequest](./puppeteer.responseforrequest.md) | Required response data to fulfill a request with. | @@ -158,7 +157,6 @@ sidebar_label: API | [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority | | [defaultArgs](./puppeteer.defaultargs.md) | | | [devices](./puppeteer.devices.md) | | -| [errors](./puppeteer.errors.md) | | | [executablePath](./puppeteer.executablepath.md) | | | [KnownDevices](./puppeteer.knowndevices.md) | A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md). | | [launch](./puppeteer.launch.md) | | diff --git a/docs/api/puppeteer.errors.md b/docs/api/puppeteer.errors.md deleted file mode 100644 index b2b1913a52c..00000000000 --- a/docs/api/puppeteer.errors.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -sidebar_label: errors ---- - -# errors variable - -> Warning: This API is now obsolete. -> -> Import error classes directly. -> -> Puppeteer methods might throw errors if they are unable to fulfill a request. For example, `page.waitForSelector(selector[, options])` might fail if the selector doesn't match any nodes during the given timeframe. -> -> For certain types of errors Puppeteer uses specific error classes. These classes are available via `puppeteer.errors`. - -#### Signature: - -```typescript -errors: PuppeteerErrors; -``` - -## Example - -An example of handling a timeout error: - -```ts -try { - await page.waitForSelector('.foo'); -} catch (e) { - if (e instanceof TimeoutError) { - // Do something if this is a timeout. - } -} -``` diff --git a/docs/api/puppeteer.protocolerror.md b/docs/api/puppeteer.protocolerror.md index 121696eca01..90d99b16136 100644 --- a/docs/api/puppeteer.protocolerror.md +++ b/docs/api/puppeteer.protocolerror.md @@ -9,10 +9,10 @@ ProtocolError is emitted whenever there is an error from the protocol. #### Signature: ```typescript -export declare class ProtocolError extends CustomError +export declare class ProtocolError extends PuppeteerError ``` -**Extends:** [CustomError](./puppeteer.customerror.md) +**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md) ## Properties diff --git a/docs/api/puppeteer.customerror.md b/docs/api/puppeteer.puppeteererror.md similarity index 51% rename from docs/api/puppeteer.customerror.md rename to docs/api/puppeteer.puppeteererror.md index e63e243516e..16a1aa65b2d 100644 --- a/docs/api/puppeteer.customerror.md +++ b/docs/api/puppeteer.puppeteererror.md @@ -1,21 +1,19 @@ --- -sidebar_label: CustomError +sidebar_label: PuppeteerError --- -# CustomError class +# PuppeteerError class -> Warning: This API is now obsolete. -> -> Do not use. +The base class for all Puppeteer-specific errors #### Signature: ```typescript -export declare class CustomError extends Error +export declare class PuppeteerError extends Error ``` **Extends:** Error ## Remarks -The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CustomError` class. +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `PuppeteerError` class. diff --git a/docs/api/puppeteer.puppeteererrors.md b/docs/api/puppeteer.puppeteererrors.md deleted file mode 100644 index 5993f942a68..00000000000 --- a/docs/api/puppeteer.puppeteererrors.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -sidebar_label: PuppeteerErrors ---- - -# PuppeteerErrors interface - -> Warning: This API is now obsolete. -> -> Do not use. - -#### Signature: - -```typescript -export interface PuppeteerErrors -``` - -## Properties - -| Property | Modifiers | Type | Description | Default | -| ------------- | --------- | ---------------------------------------------------- | ----------- | ------- | -| ProtocolError | | typeof [ProtocolError](./puppeteer.protocolerror.md) | | | -| TimeoutError | | typeof [TimeoutError](./puppeteer.timeouterror.md) | | | diff --git a/docs/api/puppeteer.timeouterror.md b/docs/api/puppeteer.timeouterror.md index 585ce8f5dc8..3fb32e3db86 100644 --- a/docs/api/puppeteer.timeouterror.md +++ b/docs/api/puppeteer.timeouterror.md @@ -9,10 +9,10 @@ TimeoutError is emitted whenever certain operations are terminated due to timeou #### Signature: ```typescript -export declare class TimeoutError extends CustomError +export declare class TimeoutError extends PuppeteerError ``` -**Extends:** [CustomError](./puppeteer.customerror.md) +**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md) ## Remarks diff --git a/docs/api/puppeteer.unsupportedoperation.md b/docs/api/puppeteer.unsupportedoperation.md index c2af3d67efb..17727494450 100644 --- a/docs/api/puppeteer.unsupportedoperation.md +++ b/docs/api/puppeteer.unsupportedoperation.md @@ -9,7 +9,7 @@ Puppeteer will throw this error if a method is not supported by the currently us #### Signature: ```typescript -export declare class UnsupportedOperation extends CustomError +export declare class UnsupportedOperation extends PuppeteerError ``` -**Extends:** [CustomError](./puppeteer.customerror.md) +**Extends:** [PuppeteerError](./puppeteer.puppeteererror.md) diff --git a/packages/puppeteer-core/src/common/Errors.ts b/packages/puppeteer-core/src/common/Errors.ts index 8225d64f070..4d0a43ea33a 100644 --- a/packages/puppeteer-core/src/common/Errors.ts +++ b/packages/puppeteer-core/src/common/Errors.ts @@ -5,11 +5,11 @@ */ /** - * @deprecated Do not use. + * The base class for all Puppeteer-specific errors * * @public */ -export class CustomError extends Error { +export class PuppeteerError extends Error { /** * @internal */ @@ -36,14 +36,14 @@ export class CustomError extends Error { * * @public */ -export class TimeoutError extends CustomError {} +export class TimeoutError extends PuppeteerError {} /** * ProtocolError is emitted whenever there is an error from the protocol. * * @public */ -export class ProtocolError extends CustomError { +export class ProtocolError extends PuppeteerError { #code?: number; #originalMessage = ''; @@ -76,49 +76,9 @@ export class ProtocolError extends CustomError { * * @public */ -export class UnsupportedOperation extends CustomError {} +export class UnsupportedOperation extends PuppeteerError {} /** * @internal */ export class TargetCloseError extends ProtocolError {} - -/** - * @deprecated Do not use. - * - * @public - */ -export interface PuppeteerErrors { - TimeoutError: typeof TimeoutError; - ProtocolError: typeof ProtocolError; -} - -/** - * @deprecated Import error classes directly. - * - * Puppeteer methods might throw errors if they are unable to fulfill a request. - * For example, `page.waitForSelector(selector[, options])` might fail if the - * selector doesn't match any nodes during the given timeframe. - * - * For certain types of errors Puppeteer uses specific error classes. These - * classes are available via `puppeteer.errors`. - * - * @example - * An example of handling a timeout error: - * - * ```ts - * try { - * await page.waitForSelector('.foo'); - * } catch (e) { - * if (e instanceof TimeoutError) { - * // Do something if this is a timeout. - * } - * } - * ``` - * - * @public - */ -export const errors: PuppeteerErrors = Object.freeze({ - TimeoutError, - ProtocolError, -});