From 3dd4dae84ca10276ab2c1f6b11725b0e62bee4fd Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 2 Mar 2018 18:51:57 +0100 Subject: [PATCH] formula: catch maths errors in constructor --- src/browser/js/app/widgets/maths/formula.js | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/browser/js/app/widgets/maths/formula.js b/src/browser/js/app/widgets/maths/formula.js index aa97854d..9632d989 100644 --- a/src/browser/js/app/widgets/maths/formula.js +++ b/src/browser/js/app/widgets/maths/formula.js @@ -84,9 +84,27 @@ module.exports = class Formula extends Widget { } - this.formula = math.compile(this.formulaString.replace(/\$\{([^\}]*)\}/g, '_$1')) + try { - this.condition = math.compile(this.conditionString.replace(/\$\{([^\}]*)\}/g, '_$1')) + this.condition = math.compile(this.conditionString.replace(/\$\{([^\}]*)\}/g, '_$1')) + delete this.errors.condition + + } catch(err) { + + this.errors.condition = 'Error parsing formula "' + this.conditionString + '" (' + err + ')' + + } + + try { + + this.formula = math.compile(this.formulaString.replace(/\$\{([^\}]*)\}/g, '_$1')) + delete this.errors.formula + + } catch(err) { + + this.errors.formula = 'Error parsing formula "' + this.conditionString + '" (' + err + ')' + + } this.conditionState = true @@ -161,7 +179,7 @@ module.exports = class Formula extends Widget { } catch(err) { - this.errors['formula'] = 'Error parsing formula "' + this.formulaString + '" (' + err + ')' + this.errors.formula = 'Error parsing formula "' + this.formulaString + '" (' + err + ')' this.value = undefined }