solana_kit_errors library

Structured error types and error-code utilities for the Solana Kit Dart SDK.

Exports SolanaError, numeric error codes, error domains, message formatting helpers, and Solana runtime/RPC error conversion utilities.

Typed Error Domains

solana_kit_errors includes domain helpers layered over numeric error codes. Use them to route error handling without hardcoding code ranges throughout your application.

import 'package:solana_kit_errors/solana_kit_errors.dart';

void handleSolanaFailure(SolanaError error) {
  if (error.isInDomain(SolanaErrorDomain.rpc)) {
    print('RPC failure: $error');
    return;
  }

  if (error.isInDomain(SolanaErrorDomain.transaction)) {
    print('Transaction failure: $error');
    return;
  }

  print('Unhandled Solana error: $error');
}

This keeps your error-routing logic readable while still preserving the exact numeric code and context payload when you need lower-level diagnostics.

Security note

Attach small, structured, non-sensitive context to SolanaError values so service boundaries can classify failures without parsing strings.

Avoid logging private keys, auth tokens, wallet session payloads, or full structured error contexts in production logs.

Classes

RpcEnumErrorConfig
Configuration for mapping RPC enum errors to SolanaError instances.
SolanaErrorContextKeys
Shared context key conventions for structured Solana diagnostics.

Enums

SolanaErrorCode
All Solana error code constants ported from the TypeScript @solana/errors package.
SolanaErrorDomain
High-level categories for SolanaErrorCode values.

Extensions

SolanaErrorCodeDomainExtension on SolanaErrorCode
Typed domain helpers for SolanaErrorCode enum values.
SolanaErrorDomainExtension on SolanaError
Typed domain helpers for SolanaError.

Constants

solanaErrorMessages → const Map<SolanaErrorCode, String>
Maps every SolanaErrorCode to its human-readable message template string.

Functions

createSolanaError(SolanaErrorCode code, {Map<String, Object?> context = const {}, Object? cause}) SolanaError
Creates a SolanaError using normalized context conventions.
createSolanaErrorContext(Map<String, Object?> context, {Object? cause}) Map<String, Object?>
Creates a normalized Solana error context map.
decodeEncodedContext(String encodedContext) Map<String, Object?>
Decodes a base64-encoded context string back into a Map.
encodeContextObject(Map<String, Object?> context) String
Encodes a context Map into a compact string representation.
getErrorMessage(SolanaErrorCode code, [Map<String, Object?> context = const {}]) String
Returns the human-readable error message for the given error code, with $variable placeholders interpolated from context.
getSolanaErrorDomain(SolanaErrorCode code) SolanaErrorDomain
Returns the SolanaErrorDomain for an error code.
getSolanaErrorFromInstructionError(num index, Object instructionError) SolanaError
Converts an instruction error from the Solana RPC into a SolanaError.
getSolanaErrorFromJsonRpcError(Object? putativeErrorResponse) SolanaError
Converts a JSON-RPC error response into a SolanaError.
getSolanaErrorFromRpcError(RpcEnumErrorConfig config, Object rpcEnumError) SolanaError
Converts an RPC enum-style error into a SolanaError.
getSolanaErrorFromTransactionError(Object transactionError) SolanaError
Converts a transaction error from the Solana RPC into a SolanaError.
isSolanaError(Object? e, [SolanaErrorCode? code]) bool
Returns true if e is a SolanaError.
isSolanaErrorCodeInDomain(SolanaErrorCode code, SolanaErrorDomain domain) bool
Returns true when code belongs to domain.
isSolanaErrorInDomain(Object? error, SolanaErrorDomain domain) bool
Returns true when error is a SolanaError in domain.
unwrapSimulationError(Object? error) Object?
Extracts the underlying cause from a simulation-related error.
wrapSolanaError(SolanaErrorCode code, Object cause, {Map<String, Object?> context = const {}}) SolanaError
Creates a SolanaError that wraps an underlying cause.

Exceptions / Errors

SolanaError
The core error class for all Solana Kit errors.