Skip to content

Commit ef4c91e

Browse files
authored
fix: removed name field in JsonRpcError class (#2590)
Signed-off-by: Logan Nguyen <[email protected]> Revert "fix: removed name field in JsonRpcError class" This reverts commit c8024e3. Signed-off-by: Logan Nguyen <[email protected]> Reapply "fix: removed name field in JsonRpcError class" This reverts commit e64d1fc.
1 parent e1ab6bf commit ef4c91e

File tree

18 files changed

+6
-96
lines changed

18 files changed

+6
-96
lines changed

charts/hedera-json-rpc-relay/postman.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@
617617
"pm.test(\"Success\", () => {",
618618
" var response = pm.response.json();",
619619
" pm.expect(response.error.code).to.equal(-32601);",
620-
" pm.expect(response.error.name).to.equal(\"Method not found\");",
621620
" pm.expect(response.error.message.endsWith(\"Unsupported JSON-RPC method\")).to.be.true;",
622621
" pm.expect(response.id).to.equal(\"test_id\");",
623622
" pm.expect(response.jsonrpc).to.equal(\"2.0\");",

packages/relay/src/lib/errors/JsonRpcError.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import constants from '../../lib/constants';
2323
export class JsonRpcError {
2424
public code: number;
2525
public message: string;
26-
public name?: string;
2726
public data?: string;
2827

29-
constructor(args: { name?: string; code: number; message: string; data?: string }, requestId?: string) {
28+
constructor(args: { code: number; message: string; data?: string }, requestId?: string) {
3029
this.code = args.code;
31-
this.name = args.name;
3230
this.message = requestId ? `[${constants.REQUEST_ID_STRING}${requestId}] ` + args.message : args.message;
3331
this.data = args.data;
3432
}
@@ -43,139 +41,114 @@ export const predefined = {
4341
}),
4442
GAS_LIMIT_TOO_HIGH: (gasLimit, maxGas) =>
4543
new JsonRpcError({
46-
name: 'gasLimit too high',
4744
code: -32005,
4845
message: `Transaction gas limit '${gasLimit}' exceeds block gas limit '${maxGas}'`,
4946
}),
5047
GAS_LIMIT_TOO_LOW: (gasLimit, requiredGas) =>
5148
new JsonRpcError({
52-
name: 'gasLimit too low',
5349
code: -32003,
5450
message: `Transaction gas limit provided '${gasLimit}' is insufficient of intrinsic gas required '${requiredGas}'`,
5551
}),
5652
GAS_PRICE_TOO_LOW: (gasPrice, minGasPrice) =>
5753
new JsonRpcError({
58-
name: 'Gas price too low',
5954
code: -32009,
6055
message: `Gas price '${gasPrice}' is below configured minimum gas price '${minGasPrice}'`,
6156
}),
6257
HBAR_RATE_LIMIT_EXCEEDED: new JsonRpcError({
63-
name: 'HBAR Rate limit exceeded',
6458
code: -32606,
6559
message: 'HBAR Rate limit exceeded',
6660
}),
6761
INSUFFICIENT_ACCOUNT_BALANCE: new JsonRpcError({
68-
name: 'Insufficient account balance',
6962
code: -32000,
7063
message: 'Insufficient funds for transfer',
7164
}),
7265
INTERNAL_ERROR: (message = '') =>
7366
new JsonRpcError({
74-
name: 'Internal error',
7567
code: -32603,
7668
message: message === '' || undefined ? 'Unknown error invoking RPC' : `Error invoking RPC: ${message}`,
7769
}),
7870
INVALID_PARAMETER: (index: number | string, message: string) =>
7971
new JsonRpcError({
80-
name: 'Invalid parameter',
8172
code: -32602,
8273
message: `Invalid parameter ${index}: ${message}`,
8374
}),
8475
INVALID_PARAMETERS: new JsonRpcError({
85-
name: 'Invalid parameters',
8676
code: -32602,
8777
message: 'Invalid params',
8878
}),
8979
INVALID_REQUEST: new JsonRpcError({
90-
name: 'Invalid request',
9180
code: -32600,
9281
message: 'Invalid request',
9382
}),
9483
IP_RATE_LIMIT_EXCEEDED: (methodName: string) =>
9584
new JsonRpcError({
96-
name: 'IP Rate limit exceeded',
9785
code: -32605,
9886
message: `IP Rate limit exceeded on ${methodName}`,
9987
}),
10088
MISSING_FROM_BLOCK_PARAM: new JsonRpcError({
101-
name: 'Missing fromBlock parameter',
10289
code: -32011,
10390
message: 'Provided toBlock parameter without specifying fromBlock',
10491
}),
10592
MISSING_REQUIRED_PARAMETER: (index: number | string) =>
10693
new JsonRpcError({
107-
name: 'Missing required parameters',
10894
code: -32602,
10995
message: `Missing value for required parameter ${index}`,
11096
}),
11197
NONCE_TOO_LOW: (nonce, currentNonce) =>
11298
new JsonRpcError({
113-
name: 'Nonce too low',
11499
code: 32001,
115100
message: `Nonce too low. Provided nonce: ${nonce}, current nonce: ${currentNonce}`,
116101
}),
117102
NONCE_TOO_HIGH: (nonce, currentNonce) =>
118103
new JsonRpcError({
119-
name: 'Nonce too high',
120104
code: 32002,
121105
message: `Nonce too high. Provided nonce: ${nonce}, current nonce: ${currentNonce}`,
122106
}),
123107
NO_MINING_WORK: new JsonRpcError({
124-
name: 'No mining work',
125108
code: -32000,
126109
message: 'No mining work available yet',
127110
}),
128111
PARSE_ERROR: new JsonRpcError({
129-
name: 'Parse error',
130112
code: -32700,
131113
message: 'Unable to parse JSON',
132114
}),
133115
RANGE_TOO_LARGE: (blockRange: number) =>
134116
new JsonRpcError({
135-
name: 'Block range too large',
136117
code: -32000,
137118
message: `Exceeded maximum block range: ${blockRange}`,
138119
}),
139120
REQUEST_BEYOND_HEAD_BLOCK: (requested: number, latest: number) =>
140121
new JsonRpcError({
141-
name: 'Incorrect block',
142122
code: -32000,
143123
message: `Request beyond head block: requested ${requested}, head ${latest}`,
144124
}),
145125
REQUEST_TIMEOUT: new JsonRpcError({
146-
name: 'Request timeout',
147126
code: -32010,
148127
message: 'Request timeout. Please try again.',
149128
}),
150129
RESOURCE_NOT_FOUND: (message = '') =>
151130
new JsonRpcError({
152-
name: 'Resource not found',
153131
code: -32001,
154132
message: `Requested resource not found. ${message}`,
155133
}),
156134
UNKNOWN_HISTORICAL_BALANCE: new JsonRpcError({
157-
name: 'Unavailable balance',
158135
code: -32007,
159136
message: 'Historical balance data is available only after 15 minutes.',
160137
}),
161138
UNSUPPORTED_CHAIN_ID: (requested: string | number, current: string | number) =>
162139
new JsonRpcError({
163-
name: 'ChainId not supported',
164140
code: -32000,
165141
message: `ChainId (${requested}) not supported. The correct chainId is ${current}`,
166142
}),
167143
UNSUPPORTED_METHOD: new JsonRpcError({
168-
name: 'Method not found',
169144
code: -32601,
170145
message: 'Unsupported JSON-RPC method',
171146
}),
172147
UNSUPPORTED_TRANSACTION_TYPE: new JsonRpcError({
173-
name: 'Unsupported transaction type',
174148
code: -32611,
175149
message: 'Unsupported transaction type',
176150
}),
177151
VALUE_TOO_LOW: new JsonRpcError({
178-
name: 'Value too low',
179152
code: -32602,
180153
message: 'Value below 10_000_000_000 wei which is 1 tinybar',
181154
}),
@@ -186,7 +159,6 @@ export const predefined = {
186159
}
187160

188161
return new JsonRpcError({
189-
name: 'Invalid Contract Address',
190162
code: -32012,
191163
message: message,
192164
});
@@ -198,7 +170,6 @@ export const predefined = {
198170
}
199171

200172
return new JsonRpcError({
201-
name: 'Non Existing Contract Address',
202173
code: -32013,
203174
message: message,
204175
});
@@ -210,97 +181,80 @@ export const predefined = {
210181
}
211182

212183
return new JsonRpcError({
213-
name: 'Non Existing Account Address',
214184
code: -32014,
215185
message: message,
216186
});
217187
},
218188
COULD_NOT_ESTIMATE_GAS_PRICE: new JsonRpcError({
219-
name: 'Could not estimate gas price',
220189
code: -32604,
221190
message: 'Error encountered estimating the gas price',
222191
}),
223192
COULD_NOT_RETRIEVE_LATEST_BLOCK: new JsonRpcError({
224-
name: 'Could not retrieve latest block',
225193
code: -32607,
226194
message: 'Error encountered retrieving latest block',
227195
}),
228196
MAX_SUBSCRIPTIONS: new JsonRpcError({
229-
name: 'Exceeded maximum allowed subscriptions',
230197
code: -32608,
231198
message: 'Exceeded maximum allowed subscriptions',
232199
}),
233200
UNSUPPORTED_HISTORICAL_EXECUTION: (blockId: string) =>
234201
new JsonRpcError({
235-
name: 'Unsupported historical block request',
236202
code: -32609,
237203
message: `Unsupported historical block identifier encountered: ${blockId}`,
238204
}),
239205
UNSUPPORTED_OPERATION: (message: string) =>
240206
new JsonRpcError({
241-
name: 'Unsupported operation',
242207
code: -32610,
243208
message: `Unsupported operation. ${message}`,
244209
}),
245210
PAGINATION_MAX: (count: number) =>
246211
new JsonRpcError({
247-
name: 'Mirror Node pagination count range too large',
248212
code: -32011,
249213
message: `Exceeded maximum mirror node pagination count: ${count}`,
250214
}),
251215
MAX_BLOCK_SIZE: (count: number) =>
252216
new JsonRpcError({
253-
name: 'Block size too large',
254217
code: -32000,
255218
message: `Exceeded max transactions that can be returned in a block: ${count}`,
256219
}),
257220
UNKNOWN_BLOCK: (msg?: string | null) =>
258221
new JsonRpcError({
259-
name: 'Unknown block',
260222
code: -39012,
261223
message: msg || 'Unknown block',
262224
}),
263225
INVALID_BLOCK_RANGE: new JsonRpcError({
264-
name: 'Invalid block range',
265226
code: -39013,
266227
message: 'Invalid block range',
267228
}),
268229
FILTER_NOT_FOUND: new JsonRpcError({
269-
name: 'Filter not found',
270230
code: -32001,
271231
message: 'Filter not found',
272232
}),
273233
TRANSACTION_SIZE_TOO_BIG: (actualSize: string, expectedSize: string) =>
274234
new JsonRpcError({
275-
name: 'Transaction size too big',
276235
code: -32201,
277236
message: `Oversized data: transaction size ${actualSize}, transaction limit ${expectedSize}`,
278237
}),
279238
BATCH_REQUESTS_DISABLED: new JsonRpcError({
280-
name: 'Batch requests disabled',
281239
code: -32202,
282240
message: 'Batch requests are disabled',
283241
}),
284242
BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED: (amount: number, max: number) =>
285243
new JsonRpcError({
286-
name: 'Batch requests amount max exceeded',
287244
code: -32203,
288245
message: `Batch request amount ${amount} exceeds max ${max}`,
289246
}),
290247
WS_BATCH_REQUESTS_DISABLED: new JsonRpcError({
291-
name: 'WS batch requests disabled',
292248
code: -32205,
293249
message: 'WS batch requests are disabled',
294250
}),
295251
WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED: (amount: number, max: number) =>
296252
new JsonRpcError({
297-
name: 'WS batch requests amount max exceeded',
298253
code: -32206,
299254
message: `Batch request amount ${amount} exceeds max ${max}`,
300255
}),
301256
INVALID_ARGUMENTS: (message: string) =>
302257
new JsonRpcError({
303-
name: 'Invalid argument',
304258
code: -32000,
305259
message: `Invalid arguments: ${message}`,
306260
}),

packages/relay/tests/assertions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export default class RelayAssertions {
1616
return await expect(method.apply(thisObj, args), `${error.message}`).to.eventually.be.rejected.and.satisfy(
1717
(err) => {
1818
if (!checkMessage) {
19-
return err.code === error.code && err.name === error.name;
19+
return err.code === error.code;
2020
}
21-
return err.code === error.code && err.name === error.name && err.message === error.message;
21+
return err.code === error.code && err.message === error.message;
2222
},
2323
);
2424
};

packages/relay/tests/lib/errors/JsonRpcError.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ describe('Errors', () => {
2525
describe('JsonRpcError', () => {
2626
it('Constructs correctly without request ID', () => {
2727
const err = new JsonRpcError({
28-
name: 'TestError',
2928
code: -32999,
3029
message: 'test error: foo',
3130
data: 'some data',
3231
});
3332
expect(err.code).to.eq(-32999);
34-
expect(err.name).to.eq('TestError');
3533
expect(err.data).to.eq('some data');
3634

3735
// Check that request ID is *not* prefixed
@@ -41,17 +39,14 @@ describe('Errors', () => {
4139
it('Constructs correctly with request ID', () => {
4240
const err = new JsonRpcError(
4341
{
44-
name: 'TestError',
4542
code: -32999,
4643
message: 'test error: foo',
4744
data: 'some data',
4845
},
4946
'abcd-1234',
5047
);
5148
expect(err.code).to.eq(-32999);
52-
expect(err.name).to.eq('TestError');
5349
expect(err.data).to.eq('some data');
54-
5550
// Check that request ID is prefixed
5651
expect(err.message).to.eq('[Request ID: abcd-1234] test error: foo');
5752
});

packages/relay/tests/lib/eth/eth_call.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ describe('@ethCall Eth Call spec', async function () {
343343

344344
const result = await ethImpl.call(callData, 'latest');
345345

346-
expect((result as JsonRpcError).name).to.equal('Non Existing Account Address');
347346
expect((result as JsonRpcError).code).to.equal(-32014);
348347
expect((result as JsonRpcError).message).to.equal(
349348
`Non Existing Account Address: ${callData.from}. Expected an Account Address.`,
@@ -401,7 +400,6 @@ describe('@ethCall Eth Call spec', async function () {
401400
const call: string | JsonRpcError = await ethImpl.call(ETH_CALL_REQ_ARGS, 'latest');
402401

403402
expect((call as JsonRpcError).code).to.equal(expectedError.code);
404-
expect((call as JsonRpcError).name).to.equal(expectedError.name);
405403
expect((call as JsonRpcError).message).to.equal(expectedError.message);
406404
});
407405

@@ -415,7 +413,6 @@ describe('@ethCall Eth Call spec', async function () {
415413

416414
expect(result).to.exist;
417415
expect((result as JsonRpcError).code).to.equal(3);
418-
expect((result as JsonRpcError).name).to.equal(undefined);
419416
expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`);
420417
expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex);
421418
});
@@ -456,7 +453,6 @@ describe('@ethCall Eth Call spec', async function () {
456453

457454
expect(result).to.exist;
458455
expect((result as JsonRpcError).code).to.equal(-32603);
459-
expect((result as JsonRpcError).name).to.equal('Internal error');
460456
expect((result as JsonRpcError).message).to.equal(
461457
'Error invoking RPC: Invalid contractCallResponse from consensus-node: undefined',
462458
);
@@ -603,7 +599,6 @@ describe('@ethCall Eth Call spec', async function () {
603599
const result = await ethImpl.call(callData, 'latest');
604600
expect(result).to.be.not.null;
605601
expect((result as JsonRpcError).code).to.eq(-32605);
606-
expect((result as JsonRpcError).name).to.eq('IP Rate limit exceeded');
607602
});
608603

609604
it('eth_call with all fields but mirrorNode throws 400', async function () {
@@ -621,7 +616,6 @@ describe('@ethCall Eth Call spec', async function () {
621616
const result = await ethImpl.call(callData, 'latest');
622617
expect(result).to.be.not.null;
623618
expect((result as JsonRpcError).code).to.eq(3);
624-
expect((result as JsonRpcError).name).to.eq(undefined);
625619
expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message);
626620
});
627621

@@ -676,7 +670,6 @@ describe('@ethCall Eth Call spec', async function () {
676670
sinon.assert.notCalled(sdkClientStub.submitContractCallQueryWithRetry);
677671
expect(result).to.not.be.null;
678672
expect((result as JsonRpcError).code).to.eq(3);
679-
expect((result as JsonRpcError).name).to.eq(undefined);
680673
expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message);
681674
});
682675

@@ -707,7 +700,6 @@ describe('@ethCall Eth Call spec', async function () {
707700

708701
expect(result).to.exist;
709702
expect((result as JsonRpcError).code).to.eq(3);
710-
expect((result as JsonRpcError).name).to.eq(undefined);
711703
expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`);
712704
expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex);
713705
});

packages/relay/tests/lib/eth/eth_common.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ describe('@ethCommon', async function () {
9797
const result = Relay.eth().getWork();
9898
expect(result).to.have.property('code');
9999
expect(result.code).to.be.equal(-32601);
100-
expect(result).to.have.property('name');
101-
expect(result.name).to.be.equal('Method not found');
102100
expect(result).to.have.property('message');
103101
expect(result.message).to.be.equal('Unsupported JSON-RPC method');
104102
});

0 commit comments

Comments
 (0)