-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: increase rpc error information propagation
- Loading branch information
Showing
12 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { RPC, RpcError } from '../../src'; | ||
|
||
describe('Error utility tests', () => { | ||
test('RpcError', () => { | ||
const baseError: RPC.Errors.UNEXPECTED_ERROR = { | ||
code: 63, | ||
message: 'An unexpected error occurred', | ||
data: 'data', | ||
}; | ||
const method = 'GET'; | ||
const error = new RpcError(baseError, method, method); | ||
|
||
expect(error.baseError).toBe(baseError); | ||
expect(error.message).toMatch(/^RPC: \S+ with params \S+/); | ||
expect(error.code).toEqual(baseError.code); | ||
expect(error.request.method).toEqual(method); | ||
expect(error.request.params).toEqual(method); | ||
|
||
expect(error.isType('BLOCK_NOT_FOUND')).toBe(false); | ||
expect(error.isType('UNEXPECTED_ERROR')).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Processes the RPC specification error types and logs the output to simplify the generation | ||
// of an error aggregating TS type and error code mapping object. Currently used in: | ||
// - src/types/errors.ts | ||
// - src/utils/errors/rpc.ts | ||
|
||
const starknet_api_openrpc = require('starknet_specs/api/starknet_api_openrpc.json'); | ||
const starknet_trace_api_openrpc = require('starknet_specs/api/starknet_trace_api_openrpc.json'); | ||
const starknet_write_api = require('starknet_specs/api/starknet_write_api.json'); | ||
|
||
const errorNameCodeMap = Object.fromEntries( | ||
Object.entries({ | ||
...starknet_trace_api_openrpc.components.errors, | ||
...starknet_write_api.components.errors, | ||
...starknet_api_openrpc.components.errors, | ||
}) | ||
.map((e) => [e[0], e[1].code]) | ||
.sort((a, b) => a[1] - b[1]) | ||
); | ||
|
||
console.log('errorCodes:'); | ||
console.log(errorNameCodeMap); | ||
console.log(); | ||
console.log('errorTypes:'); | ||
Object.keys(errorNameCodeMap).forEach((n) => console.log(`${n}: Errors.${n};`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Errors } from 'starknet-types-07'; | ||
|
||
// NOTE: generated with scripts/generateRpcErrorMap.js | ||
export type RPC_ERROR_SET = { | ||
FAILED_TO_RECEIVE_TXN: Errors.FAILED_TO_RECEIVE_TXN; | ||
NO_TRACE_AVAILABLE: Errors.NO_TRACE_AVAILABLE; | ||
CONTRACT_NOT_FOUND: Errors.CONTRACT_NOT_FOUND; | ||
BLOCK_NOT_FOUND: Errors.BLOCK_NOT_FOUND; | ||
INVALID_TXN_INDEX: Errors.INVALID_TXN_INDEX; | ||
CLASS_HASH_NOT_FOUND: Errors.CLASS_HASH_NOT_FOUND; | ||
TXN_HASH_NOT_FOUND: Errors.TXN_HASH_NOT_FOUND; | ||
PAGE_SIZE_TOO_BIG: Errors.PAGE_SIZE_TOO_BIG; | ||
NO_BLOCKS: Errors.NO_BLOCKS; | ||
INVALID_CONTINUATION_TOKEN: Errors.INVALID_CONTINUATION_TOKEN; | ||
TOO_MANY_KEYS_IN_FILTER: Errors.TOO_MANY_KEYS_IN_FILTER; | ||
CONTRACT_ERROR: Errors.CONTRACT_ERROR; | ||
TRANSACTION_EXECUTION_ERROR: Errors.TRANSACTION_EXECUTION_ERROR; | ||
CLASS_ALREADY_DECLARED: Errors.CLASS_ALREADY_DECLARED; | ||
INVALID_TRANSACTION_NONCE: Errors.INVALID_TRANSACTION_NONCE; | ||
INSUFFICIENT_MAX_FEE: Errors.INSUFFICIENT_MAX_FEE; | ||
INSUFFICIENT_ACCOUNT_BALANCE: Errors.INSUFFICIENT_ACCOUNT_BALANCE; | ||
VALIDATION_FAILURE: Errors.VALIDATION_FAILURE; | ||
COMPILATION_FAILED: Errors.COMPILATION_FAILED; | ||
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: Errors.CONTRACT_CLASS_SIZE_IS_TOO_LARGE; | ||
NON_ACCOUNT: Errors.NON_ACCOUNT; | ||
DUPLICATE_TX: Errors.DUPLICATE_TX; | ||
COMPILED_CLASS_HASH_MISMATCH: Errors.COMPILED_CLASS_HASH_MISMATCH; | ||
UNSUPPORTED_TX_VERSION: Errors.UNSUPPORTED_TX_VERSION; | ||
UNSUPPORTED_CONTRACT_CLASS_VERSION: Errors.UNSUPPORTED_CONTRACT_CLASS_VERSION; | ||
UNEXPECTED_ERROR: Errors.UNEXPECTED_ERROR; | ||
}; | ||
|
||
export type RPC_ERROR = RPC_ERROR_SET[keyof RPC_ERROR_SET]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
export * from './lib'; | ||
export * from './provider'; | ||
|
||
export * from './account'; | ||
export * from './cairoEnum'; | ||
export * from './calldata'; | ||
export * from './contract'; | ||
export * from './lib'; | ||
export * from './provider'; | ||
export * from './errors'; | ||
export * from './outsideExecution'; | ||
export * from './signer'; | ||
export * from './typedData'; | ||
export * from './cairoEnum'; | ||
export * from './transactionReceipt'; | ||
export * from './outsideExecution'; | ||
export * from './typedData'; | ||
|
||
export * as RPC from './api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { RPC_ERROR_SET } from '../../types'; | ||
|
||
// NOTE: generated with scripts/generateRpcErrorMap.js | ||
const errorCodes: { [K in keyof RPC_ERROR_SET]: RPC_ERROR_SET[K]['code'] } = { | ||
FAILED_TO_RECEIVE_TXN: 1, | ||
NO_TRACE_AVAILABLE: 10, | ||
CONTRACT_NOT_FOUND: 20, | ||
BLOCK_NOT_FOUND: 24, | ||
INVALID_TXN_INDEX: 27, | ||
CLASS_HASH_NOT_FOUND: 28, | ||
TXN_HASH_NOT_FOUND: 29, | ||
PAGE_SIZE_TOO_BIG: 31, | ||
NO_BLOCKS: 32, | ||
INVALID_CONTINUATION_TOKEN: 33, | ||
TOO_MANY_KEYS_IN_FILTER: 34, | ||
CONTRACT_ERROR: 40, | ||
TRANSACTION_EXECUTION_ERROR: 41, | ||
CLASS_ALREADY_DECLARED: 51, | ||
INVALID_TRANSACTION_NONCE: 52, | ||
INSUFFICIENT_MAX_FEE: 53, | ||
INSUFFICIENT_ACCOUNT_BALANCE: 54, | ||
VALIDATION_FAILURE: 55, | ||
COMPILATION_FAILED: 56, | ||
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57, | ||
NON_ACCOUNT: 58, | ||
DUPLICATE_TX: 59, | ||
COMPILED_CLASS_HASH_MISMATCH: 60, | ||
UNSUPPORTED_TX_VERSION: 61, | ||
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62, | ||
UNEXPECTED_ERROR: 63, | ||
}; | ||
export default errorCodes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters