{"record":{"id":"ef496a7594797a4f","repo":"FuelLabs/fuels-ts","slug":"invalid-policy-type","errorCode":"INVALID_POLICY_TYPE","errorMessage":"Invalid policy type: ${type}","messagePattern":"Invalid policy type: (.+?)","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/transactions/src/coders/policy.ts","lineNumber":109,"sourceCode":"\n    sortedPolicies.forEach(({ data, type }) => {\n      switch (type) {\n        case PolicyType.MaxFee:\n        case PolicyType.Tip:\n        case PolicyType.WitnessLimit:\n          parts.push(new BigNumberCoder('u64').encode(data));\n          break;\n\n        case PolicyType.Maturity:\n        case PolicyType.Expiration:\n          parts.push(new NumberCoder('u32', { padToWordSize: true }).encode(data));\n          break;\n        case PolicyType.Owner:\n          parts.push(new BigNumberCoder('u64').encode(data));\n          break;\n\n        default: {\n          throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type}`);\n        }\n      }\n    });\n\n    return concat(parts);\n  }\n\n  decode(data: Uint8Array, offset: number, policyTypes: number): [Policy[], number] {\n    let o = offset;\n    const policies: Policy[] = [];\n    const policyTypesArray = getPolicyTypesArray(policyTypes);\n\n    for (const policyType of policyTypesArray) {\n      switch (policyType) {\n        case PolicyType.Tip: {\n          const [tip, nextOffset] = new BigNumberCoder('u64').decode(data, o);\n          o = nextOffset;\n          policies.push({ type: PolicyType.Tip, data: tip });","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/transactions/src/coders/policy.ts#L91-L127","documentation":"Thrown by PolicyCoder.encode() when a policy's type is not one of Tip(1), WitnessLimit(2), Maturity(4), MaxFee(8), Expiration(16), or Owner(32). The encode switch falls to default. It indicates a policy constructed with an out-of-range or unsupported type value.","triggerScenarios":"Manually building a Policy object with type set to an invalid number; passing type 0 or values not in the PolicyType bitfield; version skew introducing an unknown policy type.","commonSituations":"Constructing policies from raw numbers instead of the PolicyType enum; using a type value reserved/added by a newer consensus version the SDK does not support.","solutions":["Import and use the PolicyType enum for policy.type.","Validate policy.type is one of the known PolicyType members before encoding.","Upgrade @fuel-ts/transactions if a newer policy type is required."],"exampleFix":"// before\nconst policy = { type: 64, data: bn(1) };\n\n// after\nimport { PolicyType } from '@fuel-ts/transactions';\nconst policy = { type: PolicyType.MaxFee, data: bn(1) };","handlingStrategy":"type-guard","validationCode":"import { PolicyType } from '@fuel-ts/transactions';\n\nconst VALID_POLICY_TYPES = new Set<PolicyType>([\n  PolicyType.Tip, PolicyType.WitnessLimit, PolicyType.Maturity,\n  PolicyType.MaxFee, PolicyType.Expiration, PolicyType.Owner,\n]);\npolicies.forEach(p => { if (!VALID_POLICY_TYPES.has(p.type)) throw new Error(`Bad policy type ${p.type}`); });","typeGuard":"import { PolicyType } from '@fuel-ts/transactions';\nfunction isValidPolicyType(t: number): boolean {\n  return [PolicyType.Tip, PolicyType.WitnessLimit, PolicyType.Maturity, PolicyType.MaxFee, PolicyType.Expiration, PolicyType.Owner].includes(t as PolicyType);\n}","tryCatchPattern":"try {\n  policyCoder.encode(policies, policyTypes);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_POLICY_TYPE) {\n    // replace the invalid policy.type with a valid PolicyType enum member\n  } else throw e;\n}","preventionTips":["Always use the PolicyType enum for policy.type.","Validate type membership before encoding policies from external data.","Upgrade @fuel-ts/transactions if a newer policy type is required."],"tags":["policy","encode","transaction","typescript"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}