{"record":{"id":"674b474b45ae7601","repo":"handsontable/handsontable","slug":"caught-error-message-from-hyperformula-addnamedex","errorCode":null,"errorMessage":"<caught error message from HyperFormula addNamedExpression()> (e instanceof Error ? e.message : String(e))","messagePattern":"<caught error message from HyperFormula addNamedExpression\\(\\)> \\(e instanceof Error \\? e\\.message : String\\(e\\)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"handsontable/src/plugins/formulas/engine/register.ts","lineNumber":274,"sourceCode":"export function registerNamedExpressions(\n  engineInstance: HyperFormulaEngine, namedExpressions: Record<string, unknown>[]\n) {\n  if (namedExpressions) {\n    engineInstance.suspendEvaluation();\n\n    namedExpressions.forEach((namedExp: Record<string, unknown>) => {\n      const {\n        name,\n        expression,\n        scope,\n        options\n      } = namedExp;\n\n      try {\n        engineInstance.addNamedExpression(name, expression, scope, options);\n\n      } catch (e) {\n        warn(e instanceof Error ? e.message : String(e));\n      }\n    });\n\n    engineInstance.resumeEvaluation();\n  }\n}\n\n/**\n * Sets up the sheet to work on. An existing sheet is reused; a new one is added only when there is\n * nothing to reuse.\n *\n * @param {object} engineInstance The engine instance.\n * @param {string} [sheetName] The sheet name to use. When omitted (or `null`), a new sheet is added.\n * @returns {string}\n */\nexport function setupSheet(engineInstance: HyperFormulaEngine, sheetName?: string | null) {\n  if (sheetName === undefined || sheetName === null) {\n    return engineInstance.addSheet();","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/handsontable/handsontable/blob/2c365a3291b45a331a6de1ed10a9deba683cfbc3/handsontable/src/plugins/formulas/engine/register.ts#L256-L292","documentation":"When the Formulas plugin registers named expressions through HyperFormula's `addNamedExpression()`, any thrown error (name conflict, invalid expression, bad scope) is caught and emitted as a console warning instead of interrupting grid initialization. The affected named expression is not available to formulas.","triggerScenarios":"Providing `namedExpressions: [{ name, expression, scope, options }]` where the name already exists in the engine/scope, the expression is invalid, or the scope sheet id does not exist.","commonSituations":"Re-initializing the grid (or hot reload) and re-adding the same named expression to a persistent shared engine; referencing a scope sheet index beyond the sheet count; typos in expression syntax.","solutions":["Check the warned message for the exact HyperFormula error.","Use unique names per scope, or remove the existing named expression before re-adding.","Confirm `scope` refers to an existing sheet index (omit for global scope).","Recreate the engine instance instead of reusing one that already holds the named expressions."],"exampleFix":"// before\nnamedExpressions: [{ name: 'TAX', expression: '=0.23', scope: 5 }] // sheet 5 missing\n// after\nnamedExpressions: [{ name: 'TAX', expression: '=0.23' }] // global scope, no collision","handlingStrategy":"try-catch","validationCode":"if (namedExpressions.some(ne => ne.scope !== undefined && ne.scope >= engine.countSheets())) {\n  throw new Error('named expression scope out of range');\n}","typeGuard":null,"tryCatchPattern":"try { engine.addNamedExpression(name, expression, scope, options); } catch (e) { console.warn('addNamedExpression failed:', e.message); }","preventionTips":["Keep named expression names unique per scope.","Use a fresh engine instance on re-init instead of reusing one.","Validate scope sheet indexes exist."],"tags":["formulas","hyperformula","named-expressions"],"backgroundTag":"named-expression-registration-failed","analyzedSha":"2c365a3291b45a331a6de1ed10a9deba683cfbc3","analyzedAt":"2026-09-01T10:26:16.720Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}