Skip to content

Commit

Permalink
fix: use AbortSignal.throwIfAborted (#10105)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed May 2, 2023
1 parent a856f8f commit 575f00a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 38 deletions.
1 change: 0 additions & 1 deletion docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ sidebar_label: API

| Class | Description |
| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AbortError](./puppeteer.aborterror.md) | AbortError is emitted whenever certain operations are terminated due to an abort request. |
| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). |
| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a browser instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). |
| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
Expand Down
19 changes: 0 additions & 19 deletions docs/api/puppeteer.aborterror.md

This file was deleted.

11 changes: 0 additions & 11 deletions packages/puppeteer-core/src/common/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ export class CustomError extends Error {
*/
export class TimeoutError extends CustomError {}

/**
* AbortError is emitted whenever certain operations are terminated due to
* an abort request.
*
* @remarks
* Example operations are {@link Page.waitForSelector | page.waitForSelector}.
*
* @public
*/
export class AbortError extends CustomError {}

/**
* ProtocolError is emitted whenever there is an error from the protocol.
*
Expand Down
10 changes: 5 additions & 5 deletions packages/puppeteer-core/src/common/QueryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {assert} from '../util/assert.js';
import {isErrorLike} from '../util/ErrorLike.js';
import {interpolateFunction, stringifyFunction} from '../util/Function.js';

import {AbortError} from './Errors.js';
import type {Frame} from './Frame.js';
import {transposeIterableHandle} from './HandleIterator.js';
import type {WaitForSelectorOptions} from './IsolatedWorld.js';
Expand Down Expand Up @@ -170,9 +169,7 @@ export class QueryHandler {
const {visible = false, hidden = false, timeout, signal} = options;

try {
if (signal?.aborted) {
throw new AbortError('QueryHander.waitFor has been aborted.');
}
signal?.throwIfAborted();

const handle = await frame.worlds[PUPPETEER_WORLD].waitForFunction(
async (PuppeteerUtil, query, selector, root, visible) => {
Expand Down Expand Up @@ -203,7 +200,7 @@ export class QueryHandler {

if (signal?.aborted) {
await handle.dispose();
throw new AbortError('QueryHander.waitFor has been aborted.');
throw signal.reason;
}

if (!(handle instanceof ElementHandle)) {
Expand All @@ -215,6 +212,9 @@ export class QueryHandler {
if (!isErrorLike(error)) {
throw error;
}
if (error.name === 'AbortError') {
throw error;
}
error.message = `Waiting for selector \`${selector}\` failed: ${error.message}`;
throw error;
} finally {
Expand Down
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/common/WaitTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {Poller} from '../injected/Poller.js';
import {createDeferredPromise} from '../util/DeferredPromise.js';
import {stringifyFunction} from '../util/Function.js';

import {TimeoutError, AbortError} from './Errors.js';
import {TimeoutError} from './Errors.js';
import {IsolatedWorld} from './IsolatedWorld.js';
import {LazyArg} from './LazyArg.js';
import {HandleFor} from './types.js';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class WaitTask<T = unknown> {
this.#signal?.addEventListener(
'abort',
() => {
void this.terminate(new AbortError('WaitTask has been aborted.'));
void this.terminate(this.#signal?.reason);
},
{
once: true,
Expand Down

0 comments on commit 575f00a

Please sign in to comment.