{"record":{"id":"c82fd45d43e8dd44","repo":"actualbudget/actual","slug":"failed-to-create-sheet-c82fd4","errorCode":null,"errorMessage":"Failed to create sheet","messagePattern":"Failed to create sheet","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/rules/action.ts","lineNumber":318,"sourceCode":"    if (!formula || !formula.startsWith('=')) {\n      throw new Error('Formula must start with =');\n    }\n\n    try {\n      hfInstance = HyperFormula.buildEmpty({\n        licenseKey: 'gpl-v3',\n        language: 'enUS',\n        dateFormats: ['DD/MM/YYYY', 'YYYY-MM-DD', 'YYYY/MM/DD'],\n        context: {\n          balanceOfPrefetch: transaction['_balanceOfPrefetched'] ?? new Map(),\n        },\n      });\n\n      const sheetName = hfInstance.addSheet('Sheet1');\n      const sheetId = hfInstance.getSheetId(sheetName);\n\n      if (sheetId === undefined) {\n        throw new Error('Failed to create sheet');\n      }\n\n      const fieldValues: Partial<TransactionForRules> & {\n        today: string;\n        account_name: string;\n        category_name: string;\n      } = {\n        ...transaction,\n        today: currentDay(),\n        account_name: transaction._account_name || '',\n        category_name: transaction._category_name || '',\n      };\n\n      for (const key of Object.keys(fieldValues)) {\n        if (key === '_balanceOfPrefetched') {\n          continue;\n        }\n        let cellValue: string | number | boolean;","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/rules/action.ts#L300-L336","documentation":"After building a HyperFormula instance, the code adds a worksheet named 'Sheet1' and resolves its numeric sheet id via getSheetId. If the returned id is undefined — meaning the sheet wasn't actually created or the name lookup failed — evaluation cannot proceed and it throws 'Failed to create sheet'.","triggerScenarios":"addSheet('Sheet1') failing or returning a name whose id lookup yields undefined, typically when a sheet named 'Sheet1' already exists in the instance or HyperFormula returns an unexpected result (internal/library-level failure).","commonSituations":"Reusing a HyperFormula instance where 'Sheet1' already exists; HyperFormula version changes altering addSheet/getSheetId return behavior; running out of resources in constrained environments.","solutions":["Always build a fresh HyperFormula.buildEmpty() instance per evaluation so 'Sheet1' cannot pre-exist","Check the return value of addSheet and use the returned sheet name for getSheetId","Pin/verify the HyperFormula version and its API contract for addSheet/getSheetId"],"exampleFix":"// before\nconst sheetName = hfInstance.addSheet('Sheet1');\nconst sheetId = hfInstance.getSheetId(sheetName);\n// after\nconst created = hfInstance.addSheet('Sheet1');\nconst sheetId = hfInstance.getSheetId(created ?? 'Sheet1');\nif (sheetId === undefined) throw new Error('Failed to create sheet');","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  const result = executeFormulaSync(formula, transaction);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to create sheet') {\n    // retry once with a fresh HyperFormula instance or surface an internal error\n  } else throw e;\n}","preventionTips":["Never share/reuse HyperFormula instances across evaluations","Keep the HyperFormula dependency version pinned and reviewed on upgrades","Report this as a bug if it occurs with a fresh instance — it indicates a library-level failure"],"tags":["hyperformula","internal-state","formula"],"backgroundTag":"sheet-creation-failed","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}