{"record":{"id":"223ffe47132d829c","repo":"FuelLabs/fuels-ts","slug":"parse-failed-223ffe","errorCode":"PARSE_FAILED","errorMessage":"The provided string '${str}' results in an empty output after normalization, therefore, it can't normalize string.","messagePattern":"The provided string '(.+?)' results in an empty output after normalization, therefore, it can't normalize string\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"warning","filePath":"packages/utils/src/utils/normalizeString.ts","lineNumber":28,"sourceCode":" */\nexport const normalizeString = (str: string): string => {\n  const transformations: ((s: string) => string)[] = [\n    (s) => s.replace(/\\s+/g, '-'), // spaces to -\n    (s) => s.replace(/\\./g, '-'), // dots to -\n    (s) => s.replace(/_/g, '-'), // underscore to -\n    (s) => s.replace(/-[a-z]/g, (match) => match.slice(-1).toUpperCase()), // delete '-' and capitalize the letter after them\n    (s) => s.replace(/-/g, ''), // delete any '-' left\n    (s) => s.replace(/^\\d+/, ''), // removes leading digits\n    (s) => s[0].toUpperCase() + s.slice(1), // capitalize first letter\n  ];\n\n  const output = transformations.reduce((s, t) => t(s), str);\n\n  if (output === '') {\n    const errMsg = `The provided string '${str}' results in an empty output after`.concat(\n      ` normalization, therefore, it can't normalize string.`\n    );\n    throw new FuelError(ErrorCode.PARSE_FAILED, errMsg);\n  }\n\n  return output;\n};\n","sourceCodeStart":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/utils/src/utils/normalizeString.ts#L10-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the input string contains at least one alphabetic character after separators are removed.","Prepend a non-numeric prefix (e.g. 'item-') before normalizing purely-numeric names.","Guard before calling: reject or rename strings matching /^[\\s.\\-_\\d]+$/.","Provide a fallback/default identifier when normalization would yield empty."],"exampleFix":"// before\nconst name = normalizeString('123.json'); // throws\n\n// after\nconst raw = '123.json';\nconst safe = /^[\\s.\\-_\\d]+$/.test(raw) ? `item-${raw}` : raw;\nconst name = normalizeString(safe); // 'Item123Json'","handlingStrategy":"validation","validationCode":"const EMPTY_AFTER_NORM = /^[\\s.\\-_\\d]+$/;\nfunction safeNormalize(str: string): string {\n  const input = EMPTY_AFTER_NORM.test(str) ? `item-${str}` : str;\n  return normalizeString(input);\n}","typeGuard":"const hasAlpha = (s: string): boolean => /[A-Za-z]/.test(s);","tryCatchPattern":"try {\n  return normalizeString(str);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.PARSE_FAILED) {\n    return `Item${str.replace(/[^0-9A-Za-z]/g, '')}`; // fallback name\n  }\n  throw e;\n}","preventionTips":["Ensure input has at least one alphabetic character before normalizing.","Prepend a non-numeric prefix to purely-numeric names.","Provide a default identifier when generating names from untrusted/numeric sources."],"tags":["normalize","string","codegen","naming"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}