Skip to main content

errors

This module exposes helpers for extracting and decoding transaction errors, especially viem and GMX custom errors.

Functions

extractErrorDataFromViemError

extractErrorDataFromViemError(error: any): string | undefined

Walks a viem error object and returns the first raw revert-data payload it can find.

import { extractErrorDataFromViemError } from "@gmx-io/sdk/utils/errors";

const data = extractErrorDataFromViemError(error);

tryDecodeCustomError

tryDecodeCustomError(reasonBytes: string): ParsedCustomError | undefined

Attempts to decode a GMX custom error directly from raw revert bytes.

import { tryDecodeCustomError } from "@gmx-io/sdk/utils/errors";

const decoded = tryDecodeCustomError("0x08c379a0...");

decodeErrorFromViemError

decodeErrorFromViemError(error: any): ParsedCustomError | undefined

Combines raw-data extraction and GMX custom-error decoding in one step.

import { decodeErrorFromViemError } from "@gmx-io/sdk/utils/errors";

const decoded = decodeErrorFromViemError(error);

parseError

parseError(error: ErrorLike | string | undefined, errorDepth = 0): ErrorData | undefined

Normalizes nested transaction errors into a structured object with context, decoded contract error details, and user-error classification.

import { parseError } from "@gmx-io/sdk/utils/errors";

const parsed = parseError(error);
console.log(parsed?.contractError, parsed?.errorMessage);