{"record":{"id":"f3430423f7a59ecd","repo":"FuelLabs/fuels-ts","slug":"parse-failed-f34304","errorCode":"PARSE_FAILED","errorMessage":"Failed to parse the error object. The required 'code' property is missing.","messagePattern":"Failed to parse the error object\\. The required 'code' property is missing\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/errors/src/fuel-error.ts","lineNumber":15,"sourceCode":"import { versions } from '@fuel-ts/versions';\n\nimport { ErrorCode } from './error-codes';\n\nexport class FuelError extends Error {\n  static readonly CODES = ErrorCode;\n  readonly VERSIONS = versions;\n  readonly metadata: Record<string, unknown>;\n  readonly rawError: unknown;\n\n  static parse(e: unknown) {\n    const error = e as FuelError;\n\n    if (error.code === undefined) {\n      throw new FuelError(\n        ErrorCode.PARSE_FAILED,\n        \"Failed to parse the error object. The required 'code' property is missing.\"\n      );\n    }\n\n    const enumValues = Object.values(ErrorCode);\n    const codeIsKnown = enumValues.includes(error.code);\n\n    if (!codeIsKnown) {\n      throw new FuelError(\n        ErrorCode.PARSE_FAILED,\n        `Unknown error code: ${error.code}. Accepted codes: ${enumValues.join(', ')}.`\n      );\n    }\n\n    return new FuelError(error.code, error.message, error.metadata, error.rawError);\n  }\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/errors/src/fuel-error.ts#L1-L33","documentation":"Thrown by FuelError.parse() when the input object has no `code` property. parse() expects a serialized FuelError shape; `code` is the discriminator it uses to reconstruct the error, so its absence means the input was never a FuelError. This guards the parser against plain Error objects, network error bodies, and arbitrary JSON.","triggerScenarios":"Calling `FuelError.parse(e)` on a plain `Error`, an HTTP error response body, a `TypeError`, or any object that does not carry a `code` field.","commonSituations":"Generic catch blocks that funnel every caught value through FuelError.parse; deserializing error JSON from a server that wraps errors differently; passing the result of `.toJSON()` on a non-Fuel error.","solutions":["Guard the input before parsing: only call parse() when the object looks like a FuelError.","Use `instanceof FuelError` first and skip parse() for already-typed errors.","When receiving errors over the wire, confirm the source serializes with `code` before calling parse()."],"exampleFix":"// before\nconst err = FuelError.parse(maybeError);\n// after — narrow first\nfunction toFuelError(e: unknown) {\n  if (e instanceof FuelError) return e;\n  if (e && typeof e === 'object' && 'code' in e && typeof (e as any).code === 'string') {\n    return FuelError.parse(e);\n  }\n  return new FuelError(FuelError.CODES.UNKNOWN, (e as Error)?.message ?? 'Unknown error');\n}","handlingStrategy":"type-guard","validationCode":"const looksLikeFuelError = (e: unknown): boolean =>\n  !!e && typeof e === 'object' && 'code' in e && typeof (e as any).code !== 'undefined';","typeGuard":"import { ErrorCode, FuelError } from '@fuel-ts/errors';\nfunction isFuelErrorShape(e: unknown): e is { code: ErrorCode; message: string; metadata?: unknown } {\n  return !!e && typeof e === 'object' && 'code' in e;\n}","tryCatchPattern":"try {\n  return FuelError.parse(input);\n} catch (e) {\n  if (e instanceof FuelError && e.code === FuelError.CODES.PARSE_FAILED) {\n    return new FuelError(FuelError.CODES.UNKNOWN, String((input as Error)?.message ?? input));\n  }\n  throw e;\n}","preventionTips":["Check `instanceof FuelError` before calling parse().","Only feed parse() objects you serialized from a FuelError.","Never pipe arbitrary caught values into parse(); narrow first."],"tags":["errors","parsing","serialization","type-narrowing"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}