FuelLabs/fuels-ts · warning · FuelError

PARSE_FAILED

PARSE_FAILED

Error message

The provided string '${str}' results in an empty output after normalization, therefore, it can't normalize string.

What it means

Thrown by normalizeString when the cascade of transformations (spaces/dots/underscores to '-', kebab-casing, removing remaining '-', stripping leading digits, capitalizing) reduces the input to an empty string. The pipeline can produce '' for inputs that consist only of digits, separators, or whitespace, which is reported as a parse failure.

Source

Thrown at packages/utils/src/utils/normalizeString.ts:28

 */
export const normalizeString = (str: string): string => {
  const transformations: ((s: string) => string)[] = [
    (s) => s.replace(/\s+/g, '-'), // spaces to -
    (s) => s.replace(/\./g, '-'), // dots to -
    (s) => s.replace(/_/g, '-'), // underscore to -
    (s) => s.replace(/-[a-z]/g, (match) => match.slice(-1).toUpperCase()), // delete '-' and capitalize the letter after them
    (s) => s.replace(/-/g, ''), // delete any '-' left
    (s) => s.replace(/^\d+/, ''), // removes leading digits
    (s) => s[0].toUpperCase() + s.slice(1), // capitalize first letter
  ];

  const output = transformations.reduce((s, t) => t(s), str);

  if (output === '') {
    const errMsg = `The provided string '${str}' results in an empty output after`.concat(
      ` normalization, therefore, it can't normalize string.`
    );
    throw new FuelError(ErrorCode.PARSE_FAILED, errMsg);
  }

  return output;
};

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Ensure the input string contains at least one alphabetic character after separators are removed.
  2. Prepend a non-numeric prefix (e.g. 'item-') before normalizing purely-numeric names.
  3. Guard before calling: reject or rename strings matching /^[\s.\-_\d]+$/.
  4. Provide a fallback/default identifier when normalization would yield empty.

Example fix

// before
const name = normalizeString('123.json'); // throws

// after
const raw = '123.json';
const safe = /^[\s.\-_\d]+$/.test(raw) ? `item-${raw}` : raw;
const name = normalizeString(safe); // 'Item123Json'
Defensive patterns

Strategy: validation

Validate before calling

const EMPTY_AFTER_NORM = /^[\s.\-_\d]+$/;
function safeNormalize(str: string): string {
  const input = EMPTY_AFTER_NORM.test(str) ? `item-${str}` : str;
  return normalizeString(input);
}

Type guard

const hasAlpha = (s: string): boolean => /[A-Za-z]/.test(s);

Try / catch

try {
  return normalizeString(str);
} catch (e) {
  if (e instanceof FuelError && e.code === ErrorCode.PARSE_FAILED) {
    return `Item${str.replace(/[^0-9A-Za-z]/g, '')}`; // fallback name
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling normalizeString(str) where str is something like '123', '---', '...', ' ', '__', '-1-', or any mix whose only non-separator content is leading digits. After replacements and the leading-digit strip, output becomes '' and the guard throws.

Common situations: Generating an identifier (e.g. a class name) from a filename that is purely numeric like '123.json'. Passing a filename with no alphabetic characters. Using normalizeString on user-supplied or auto-generated names that lack letters. Tooling that derives names from indices.

Related errors


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