Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable eslint rule and reject with errors instead of strings #42

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default [
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/restrict-template-expressions': 'error',
'@typescript-eslint/unbound-method': 'off',
Expand Down
1 change: 1 addition & 0 deletions examples/rpc-transport-throttled/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function getThrottledTransport<TClusterUrl extends ClusterUrl>(
} as QueuedRequest<TClusterUrl>);
if (config.signal) {
config.signal.addEventListener('abort', function () {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(this.reason);
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/promises/src/abortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortS
// want to throw even if the input promise's result is ready
new Promise<never>((_, reject) => {
if (abortSignal.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(abortSignal.reason);
} else {
abortSignal.addEventListener('abort', function () {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(this.reason);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createWebSocketChannel({
url,
}: Config): Promise<RpcSubscriptionsChannel<WebSocketMessage, string>> {
if (signal.aborted) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
return Promise.reject(signal.reason);
}
let bufferDrainWatcher: Readonly<{ onCancel(): void; promise: Promise<void> }> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export async function executeRpcPubSubSubscriptionPlan<TNotification>({
subscriptionId = undefined;
channel.send(unsubscribePayload).catch(() => {});
}
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(this.reason);
}
if (signal.aborted) {
Expand Down
1 change: 1 addition & 0 deletions packages/rpc/src/__tests__/rpc-request-coalescer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('RPC request coalescer', () => {
return await new Promise((resolve, reject) => {
transportResponsePromise = resolve;
signal?.addEventListener('abort', (e: AbortSignalEventMap['abort']) => {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject((e.target as AbortSignal).reason);
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/rpc/src/rpc-request-coalescer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function getRpcTransportWithRequestCoalescing<TTransport extends RpcTrans
abortController.abort((EXPLICIT_ABORT_TOKEN ||= createExplicitAbortToken()));
}
});
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject((e.target as AbortSignal).reason);
};
signal.addEventListener('abort', handleAbort);
Expand Down