Skip to content

Commit

Permalink
Merge pull request #120 from laucheukhim/fix/formulajs-error
Browse files Browse the repository at this point in the history
Handle formula.js error that is returned instead of thrown
  • Loading branch information
fabiooshiro authored Jul 22, 2024
2 parents 50a5c79 + fd37dbe commit c37597c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/UserFnExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = function UserFnExecutor(user_function) {
var result;
try {
result = user_function.apply(self, self.args.map(f => f.calc()));
if (result instanceof Error) {
throw result;
}
} catch (e) {
const errorValue = getErrorValueByMessage(e.message)
if (user_function.name === 'is_blank'
Expand Down
11 changes: 11 additions & 0 deletions test/5-formulajs-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ describe('formulajs integration', function() {
assert.strictEqual(XLSX_CALC.xlsx_Fx.TRUNC === formulajs.TRUNC, true);
});
});
describe('UserFnExecutor()', function() {
it('handles error that is returned instead of thrown', function() {
XLSX_CALC.import_functions(formulajs);
var workbook = {};
workbook.Sheets = {};
workbook.Sheets.Sheet1 = {};
workbook.Sheets.Sheet1.A2 = {f: 'AVERAGE(A1)'};
XLSX_CALC(workbook);
assert.strictEqual(workbook.Sheets.Sheet1.A2.w, '#DIV/0!');
});
})
});

0 comments on commit c37597c

Please sign in to comment.