Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Correct omissions from #2236
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Mar 4, 2024
1 parent fc11993 commit c971889
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
8 changes: 4 additions & 4 deletions packages/errors/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ import {
SOLANA_ERROR__NOT_ALL_ACCOUNTS_DECODED,
SOLANA_ERROR__PROGRAM_DERIVED_ADDRESS_BUMP_SEED_OUT_OF_RANGE,
SOLANA_ERROR__RPC_INTEGER_OVERFLOW,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN,
SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__SIGNER_ADDRESS_CANNOT_HAVE_MULTIPLE_SIGNERS,
SOLANA_ERROR__SIGNER_EXPECTED_KEY_PAIR_SIGNER,
SOLANA_ERROR__SIGNER_EXPECTED_MESSAGE_MODIFYING_SIGNER,
Expand All @@ -99,7 +100,6 @@ import {
SOLANA_ERROR__SIGNER_EXPECTED_TRANSACTION_PARTIAL_SIGNER,
SOLANA_ERROR__SIGNER_EXPECTED_TRANSACTION_SENDING_SIGNER,
SOLANA_ERROR__SIGNER_EXPECTED_TRANSACTION_SIGNER,
SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE,
SOLANA_ERROR__TRANSACTION_ERROR_DUPLICATE_INSTRUCTION,
SOLANA_ERROR__TRANSACTION_ERROR_INSUFFICIENT_FUNDS_FOR_RENT,
Expand Down Expand Up @@ -327,7 +327,7 @@ export type SolanaErrorContext = DefaultUnspecifiedErrorContextToUndefined<
message: string;
statusCode: number;
};
[SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT]: {
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT]: {
errorEvent: Event;
};
[SOLANA_ERROR__SIGNER_ADDRESS_CANNOT_HAVE_MULTIPLE_SIGNERS]: {
Expand Down Expand Up @@ -357,7 +357,7 @@ export type SolanaErrorContext = DefaultUnspecifiedErrorContextToUndefined<
[SOLANA_ERROR__SIGNER_EXPECTED_TRANSACTION_SIGNER]: {
address: string;
};
[SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST]: {
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST]: {
notificationName: string;
};
[SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE]: {
Expand Down
29 changes: 15 additions & 14 deletions packages/errors/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ import {
SOLANA_ERROR__PROGRAM_ADDRESS_ENDS_WITH_PDA_MARKER,
SOLANA_ERROR__PROGRAM_DERIVED_ADDRESS_BUMP_SEED_OUT_OF_RANGE,
SOLANA_ERROR__RPC_INTEGER_OVERFLOW,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CONNECTION_CLOSED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN,
SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CONNECTION_CLOSED,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__SIGNER_ADDRESS_CANNOT_HAVE_MULTIPLE_SIGNERS,
SOLANA_ERROR__SIGNER_EXPECTED_KEY_PAIR_SIGNER,
SOLANA_ERROR__SIGNER_EXPECTED_MESSAGE_MODIFYING_SIGNER,
Expand All @@ -115,8 +117,6 @@ import {
SOLANA_ERROR__SIGNER_EXPECTED_TRANSACTION_SIGNER,
SOLANA_ERROR__SIGNER_TRANSACTION_CANNOT_HAVE_MULTIPLE_SENDING_SIGNERS,
SOLANA_ERROR__SIGNER_TRANSACTION_SENDING_SIGNER_MISSING,
SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID,
SOLANA_ERROR__SUBTLE_CRYPTO_DIGEST_MISSING,
SOLANA_ERROR__SUBTLE_CRYPTO_ED25519_ALGORITHM_MISSING,
SOLANA_ERROR__SUBTLE_CRYPTO_EXPORT_FUNCTION_MISSING,
Expand Down Expand Up @@ -333,14 +333,20 @@ export const SolanaErrorMessages: Readonly<{
'The $argumentLabel argument to the `$methodName` RPC method$optionalPathLabel was ' +
'`$value`. This number is unsafe for use with the Solana JSON-RPC because it exceeds ' +
'`Number.MAX_SAFE_INTEGER`.',
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST]:
"Either the notification name must end in 'Notifications' or the API must supply a " +
"subscription creator function for the notification '$notificationName' to map between " +
'the notification name and the subscribe/unsubscribe method names.',
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID]:
'Failed to obtain a subscription id from the server',
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED]:
'WebSocket was closed before payload could be added to the send buffer',
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CONNECTION_CLOSED]: 'WebSocket connection closed',
[SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT]: 'WebSocket failed to connect',
[SOLANA_ERROR__RPC_TRANSPORT_HEADER_FORBIDDEN]:
'HTTP header(s) forbidden: $headers. Learn more at ' +
'https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.',
[SOLANA_ERROR__RPC_TRANSPORT_HTTP_ERROR]: 'HTTP error ($statusCode): $message',
[SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED]:
'WebSocket was closed before payload could be added to the send buffer',
[SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CONNECTION_CLOSED]: 'WebSocket connection closed',
[SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT]: 'WebSocket failed to connect',
[SOLANA_ERROR__SIGNER_ADDRESS_CANNOT_HAVE_MULTIPLE_SIGNERS]:
'Multiple distinct signers were identified for address `$address`. Please ensure that ' +
'you are using the same signer instance for each address.',
Expand All @@ -365,11 +371,6 @@ export const SolanaErrorMessages: Readonly<{
[SOLANA_ERROR__SIGNER_TRANSACTION_SENDING_SIGNER_MISSING]:
'No `TransactionSendingSigner` was identified. Please provide a valid ' +
'`ITransactionWithSingleSendingSigner` transaction.',
[SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST]:
"Either the notification name must end in 'Notifications' or the API must supply a " +
"subscription creator function for the notification '$notificationName' to map between " +
'the notification name and the subscribe/unsubscribe method names.',
[SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID]: 'Failed to obtain a subscription id from the server',
[SOLANA_ERROR__SUBTLE_CRYPTO_DIGEST_MISSING]: 'No digest implementation could be found.',
[SOLANA_ERROR__SUBTLE_CRYPTO_ED25519_ALGORITHM_MISSING]:
'This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and ' +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID,
SolanaError,
} from '@solana/errors';
import { createRpcMessage, RpcError } from '@solana/rpc-spec-types';
Expand Down Expand Up @@ -229,15 +229,15 @@ describe('JSON-RPC 2.0 Subscriptions', () => {
.thingNotifications()
.subscribe({ abortSignal: new AbortController().signal });
await expect(thingNotificationsPromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID),
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID),
);
},
);
it("fatals when called with a method that does not end in 'Notifications'", () => {
expect(() => {
rpc.nonConformingNotif().subscribe({ abortSignal: new AbortController().signal });
}).toThrow(
new SolanaError(SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST, {
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST, {
notificationName: 'nonConformingNotif',
}),
);
Expand All @@ -256,7 +256,7 @@ describe('JSON-RPC 2.0 Subscriptions', () => {
});
const subscribePromise = rpc.thingNotifications().subscribe({ abortSignal: new AbortController().signal });
await expect(subscribePromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID),
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID),
);
});
it('fatals when the server responds with an error', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/rpc-subscriptions-spec/src/rpc-subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID,
SolanaError,
} from '@solana/errors';
import {
Expand Down Expand Up @@ -84,7 +84,7 @@ function makeProxy<TRpcSubscriptionsApiMethods, TRpcSubscriptionsTransport exten
const notificationName = p.toString();
const createRpcSubscription = Reflect.get(target, notificationName, receiver);
if (p.toString().endsWith('Notifications') === false && !createRpcSubscription) {
throw new SolanaError(SOLANA_ERROR__SUBSCRIPTION_CANNOT_CREATE_SUBSCRIPTION_REQUEST, {
throw new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_CANNOT_CREATE_SUBSCRIPTION_REQUEST, {
notificationName,
});
}
Expand Down Expand Up @@ -167,7 +167,7 @@ function createPendingRpcSubscription<
}
}
if (subscriptionId == null) {
throw new SolanaError(SOLANA_ERROR__SUBSCRIPTION_EXPECTED_SERVER_SUBSCRIPTION_ID);
throw new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_EXPECTED_SERVER_SUBSCRIPTION_ID);
}
/**
* STEP 3: Return an iterable that yields notifications for this subscription id.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT,
SolanaError,
} from '@solana/errors';
import WS from 'jest-websocket-mock';
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('createWebSocketConnection', () => {
url: 'ws://fake', // Wrong URL!
});
await expect(connectionPromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT, {
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT, {
errorEvent: {} as Event,
}),
);
Expand All @@ -61,7 +61,7 @@ describe('createWebSocketConnection', () => {
expect(client).toHaveProperty('readyState', WebSocket.CONNECTING);
abortController.abort();
await expect(connectionPromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT, {
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT, {
errorEvent: {} as Event,
}),
);
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('RpcWebSocketConnection', () => {
const sendPromise = connection.send({ some: 'message' });
abortController.abort();
await expect(sendPromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED),
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED),
);
});
it('fatals when the connection encounters an error while a message is queued', async () => {
Expand All @@ -243,7 +243,7 @@ describe('RpcWebSocketConnection', () => {
wasClean: false,
});
await expect(sendPromise).rejects.toThrow(
new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED),
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CONNECTION_CLOSED,
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CONNECTION_CLOSED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT,
SolanaError,
} from '@solana/errors';
import WebSocket from '@solana/ws-impl';
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function createWebSocketConnection({
function handleError(ev: Event) {
if (!hasConnected) {
reject(
new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_FAILED_TO_CONNECT, {
new SolanaError(SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_FAILED_TO_CONNECT, {
errorEvent: ev,
}),
);
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function createWebSocketConnection({
clearInterval(intervalId);
reject(
new SolanaError(
SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CLOSED_BEFORE_MESSAGE_BUFFERED,
),
);
};
Expand Down Expand Up @@ -158,9 +158,12 @@ export async function createWebSocketConnection({
if (e === EXPLICIT_ABORT_TOKEN) {
return;
} else {
throw new SolanaError(SOLANA_ERROR__RPC_WEBSOCKET_TRANSPORT_CONNECTION_CLOSED, {
cause: e,
});
throw new SolanaError(
SOLANA_ERROR__RPC_SUBSCRIPTIONS_TRANSPORT_CONNECTION_CLOSED,
{
cause: e,
},
);
}
}
}
Expand Down

0 comments on commit c971889

Please sign in to comment.