UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

95 lines (94 loc) 5.67 kB
import { SDKError, ErrorSeverity, ErrorCategory } from './base.js'; /** * Instruction decoding failed */ export class DecoderError extends SDKError { constructor(message, instructionData, programId, context = {}, options = {}) { super(message, 'DECODER_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { programId }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The instruction could not be decoded. This may indicate an unknown instruction type or corrupted data.' })); this.instructionData = instructionData; this.programId = programId; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { instructionData: this.instructionData, programId: this.programId }); } } /** * No decoder registered for program */ export class DecoderNotFoundError extends SDKError { constructor(programId, context = {}, options = {}) { super(`No decoder found for program: ${programId}`, 'DECODER_NOT_FOUND', ErrorSeverity.LOW, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { programId }), Object.assign(Object.assign({}, options), { retryable: false, solution: `Register a decoder for program ${programId} using the DecoderRegistry.registerDecoder() method.` })); this.programId = programId; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { programId: this.programId }); } } /** * Invalid instruction data format */ export class InvalidInstructionDataError extends SDKError { constructor(instructionData, expectedFormat, context = {}, options = {}) { const message = expectedFormat ? `Invalid instruction data format. Expected: ${expectedFormat}` : 'Invalid instruction data format'; super(message, 'INVALID_INSTRUCTION_DATA', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'The instruction data format is invalid. Check that the data is properly encoded and matches the expected format.' })); this.instructionData = instructionData; this.expectedFormat = expectedFormat; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { instructionData: this.instructionData, expectedFormat: this.expectedFormat }); } } /** * Token metadata decoding failed */ export class TokenMetadataDecodingError extends SDKError { constructor(message, mintAddress, metadataAccount, context = {}, options = {}) { super(`Token metadata decoding failed: ${message}`, 'TOKEN_METADATA_DECODING_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { account: metadataAccount || mintAddress }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The token metadata could not be decoded. This may indicate an invalid metadata account or unsupported metadata format.' })); this.mintAddress = mintAddress; this.metadataAccount = metadataAccount; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { mintAddress: this.mintAddress, metadataAccount: this.metadataAccount }); } } /** * NFT metadata decoding failed */ export class NFTMetadataDecodingError extends SDKError { constructor(message, nftAddress, metadataUri, context = {}, options = {}) { super(`NFT metadata decoding failed: ${message}`, 'NFT_METADATA_DECODING_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { account: nftAddress }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The NFT metadata could not be decoded. Check that the metadata URI is accessible and contains valid JSON.' })); this.nftAddress = nftAddress; this.metadataUri = metadataUri; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { nftAddress: this.nftAddress, metadataUri: this.metadataUri }); } } /** * Account data decoding failed */ export class AccountDataDecodingError extends SDKError { constructor(message, accountAddress, accountType, context = {}, options = {}) { super(`Account data decoding failed: ${message}`, 'ACCOUNT_DATA_DECODING_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { account: accountAddress }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The account data could not be decoded. This may indicate an unsupported account type or corrupted data.' })); this.accountAddress = accountAddress; this.accountType = accountType; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { accountAddress: this.accountAddress, accountType: this.accountType }); } } /** * Swap instruction decoding failed */ export class SwapDecodingError extends SDKError { constructor(message, swapProgram, swapType, context = {}, options = {}) { super(`Swap instruction decoding failed: ${message}`, 'SWAP_DECODING_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.DECODER, Object.assign(Object.assign({}, context), { programId: swapProgram }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The swap instruction could not be decoded. This may indicate an unsupported swap program or instruction format.' })); this.swapProgram = swapProgram; this.swapType = swapType; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { swapProgram: this.swapProgram, swapType: this.swapType }); } }