FuelLabs/fuels-ts · error · FuelError

JSON_ABI_ERROR

JSON_ABI_ERROR

Error message

Couldn't extract struct name with: '${regex}'.\n\nCheck your JSON ABI.\n\n[source]\n${JSON.stringify(rawAbiType, null, 2)}

What it means

extractStructName runs a regex against rawAbiType.type to pull the struct name out of the type string. If neither capture group 2 nor group 1 yields a value, the type string does not match the expected struct-naming shape and the typegen cannot produce a class name for the struct.

Source

Thrown at packages/abi-typegen/src/utils/extractStructName.ts:16

import { ErrorCode, FuelError } from '@fuel-ts/errors';

import type { JsonAbiType } from '../types/interfaces/JsonAbi';

export function extractStructName(params: { rawAbiType: JsonAbiType; regex: RegExp }) {
  const { rawAbiType, regex } = params;

  const matches = rawAbiType.type.match(regex);
  const match = matches?.[2] ?? matches?.[1];

  if (!match) {
    let errorMessage = `Couldn't extract struct name with: '${regex}'.\n\n`;
    errorMessage += `Check your JSON ABI.\n\n[source]\n`;
    errorMessage += `${JSON.stringify(rawAbiType, null, 2)}`;

    throw new FuelError(ErrorCode.JSON_ABI_ERROR, errorMessage);
  }

  return match;
}

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Inspect the offending rawAbiType printed in the error to see its `type` field.
  2. Regenerate the ABI from current Sway source with the compiler version the SDK targets.
  3. Correct the malformed `type` string so the struct name regex matches.
Defensive patterns

Strategy: validation

Validate before calling

function assertStructNameExtractable(rawAbiType: JsonAbiType, regex: RegExp) {
  const m = rawAbiType.type.match(regex);
  if (!m && !m?.[1] && !m?.[2]) {
    throw new Error(`cannot extract struct name from type: ${rawAbiType.type}`);
  }
}

Prevention

When it happens

Trigger: An ABI struct-type entry whose `type` field does not match the supplied struct-name regex (malformed struct declaration); tooling emits a struct type string in an unexpected format; manual ABI edit broke the type field.

Common situations: ABI generated by an unsupported/old Sway version; hand-edited struct type strings; ABI converted between formats losing the struct name token.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/2d475d322f75d7aa. Report an issue: GitHub.