formula: catch maths errors in constructor

This commit is contained in:
jean-emmanuel 2018-03-02 18:51:57 +01:00
parent c7e78cf6c4
commit a0bf06f8e9

View file

@ -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
}