{"record":{"id":"8beef7c7605a9908","repo":"FuelLabs/fuels-ts","slug":"invalid-ttl","errorCode":"INVALID_TTL","errorMessage":"Invalid TTL: ${this.ttl}. Use a value greater than zero.","messagePattern":"Invalid TTL: (.+?)\\. Use a value greater than zero\\.","errorType":"validation","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/providers/resource-cache.ts","lineNumber":27,"sourceCode":"} from './transaction-request';\n\ntype ResourcesOwnersMap = Map<string, { utxos: Set<string>; messages: Set<string> }>;\n\ninterface TransactionResourcesCache {\n  owners: ResourcesOwnersMap;\n  timestamp: number;\n}\n\nconst cache = new Map<string, TransactionResourcesCache>();\n\nexport class ResourceCache {\n  readonly ttl: number;\n\n  constructor(ttl: number) {\n    this.ttl = ttl; // TTL in milliseconds\n\n    if (typeof ttl !== 'number' || this.ttl <= 0) {\n      throw new FuelError(\n        ErrorCode.INVALID_TTL,\n        `Invalid TTL: ${this.ttl}. Use a value greater than zero.`\n      );\n    }\n  }\n\n  // Add resources to the cache\n  set(transactionId: string, inputs: TransactionRequestInput[]): void {\n    const transactionResourceCache = this.setupResourcesCache(inputs);\n    cache.set(transactionId, transactionResourceCache);\n  }\n\n  unset(transactionId: string): void {\n    cache.delete(transactionId);\n  }\n\n  getActiveData(owner: string) {\n    const activeData: { utxos: string[]; messages: string[] } = { utxos: [], messages: [] };","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/providers/resource-cache.ts#L9-L45","documentation":"Thrown by the ResourceCache constructor when ttl is not a positive finite number. The cache evicts entries based on currentTime - timestamp < ttl, so a non-positive or non-numeric ttl would make every entry either instantly expired or never compared correctly. The guard enforces typeof ttl === 'number' && ttl > 0.","triggerScenarios":"Constructing new ResourceCache(ttl) with ttl <= 0, NaN, undefined (passed through as NaN), or a non-number; passing a config value parsed from env as a string; defaulting to 0 to 'disable' caching (the API does not support 0 as disable).","commonSituations":"Env var RESOURCE_CACHE_TTL set to '0' or empty and Number()-coerced to 0/NaN; passing milliseconds vs seconds confusion leading to a tiny value rounded to 0; intent to disable caching by passing 0 (use undefined instead — Provider sets cache = undefined when resourceCacheTTL is not provided).","solutions":["Pass a positive integer number of milliseconds (e.g. 5000 for 5s).","To disable caching, do not construct ResourceCache / pass resourceCacheTTL as undefined to the Provider.","Validate env-derived TTL: const ttl = Number(process.env.TTL); if (!Number.isFinite(ttl) || ttl <= 0) skip cache.","Document units (milliseconds) at the call site to avoid seconds/ms confusion."],"exampleFix":"// before\nconst cache = new ResourceCache(0); // intent: disable\n// or\nconst cache = new ResourceCache(Number(process.env.CACHE_TTL)); // NaN when unset\n\n// after — pass a positive ttl, or disable by omitting the cache\nconst ttl = Number(process.env.CACHE_TTL);\nconst cache = Number.isFinite(ttl) && ttl > 0 ? new ResourceCache(ttl) : undefined;\n\n// Provider usage: omit resourceCacheTTL to disable\nconst provider = new Provider(url, { resourceCacheTTL: undefined });","handlingStrategy":"validation","validationCode":"function makeResourceCache(ttlFromEnv?: string) {\n  const ttl = Number(ttlFromEnv);\n  if (!Number.isFinite(ttl) || ttl <= 0) return undefined; // disables cache\n  return new ResourceCache(ttl);\n}","typeGuard":"function isPositiveTtl(ttl: unknown): ttl is number {\n  return typeof ttl === 'number' && Number.isFinite(ttl) && ttl > 0;\n}","tryCatchPattern":"import { FuelError, ErrorCode } from '@fuel-ts/errors';\nlet cache;\ntry {\n  cache = new ResourceCache(ttl);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_TTL) {\n    cache = undefined; // disable caching rather than crash\n  } else throw e;\n}","preventionTips":["Pass a positive integer number of milliseconds for TTL.","To disable caching, omit resourceCacheTTL on the Provider instead of passing 0.","Validate env-derived TTLs with Number.isFinite and > 0 before use."],"tags":["cache","config","validation","provider"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}