Improve error messages

This commit is contained in:
Pieter Vander Vennet 2022-06-09 16:50:53 +02:00
parent adcdf4f18a
commit b9cc56bbc5
5 changed files with 43 additions and 36 deletions

View file

@ -172,15 +172,21 @@ export default class TagRenderingConfig {
this.mappings = json.mappings.map((mapping, i) => {
const ctx = `${translationKey}.mappings.${i}`
if (mapping.if === undefined) {
throw `${ctx}: Invalid mapping: "if" is not defined in ${JSON.stringify(mapping)}`
}
if (mapping.then === undefined) {
throw `${ctx}: Invalid mapping: if without body`
if(mapping["render"] !== undefined){
throw `${ctx}: Invalid mapping: no 'then'-clause found. You might have typed 'render' instead of 'then', change it in ${JSON.stringify(mapping)}`
}
throw `${ctx}: Invalid mapping: no 'then'-clause found in ${JSON.stringify(mapping)}`
}
if (mapping.ifnot !== undefined && !this.multiAnswer) {
throw `${ctx}: Invalid mapping: ifnot defined, but the tagrendering is not a multianswer`
throw `${ctx}: Invalid mapping: 'ifnot' is defined, but the tagrendering is not a multianswer. Either remove ifnot or set 'multiAnswer:true' to enable checkboxes instead of radiobuttons`
}
if (mapping.if === undefined) {
throw `${ctx}: Invalid mapping: "if" is not defined, but the tagrendering is not a multianswer`
if(mapping["render"] !== undefined){
throw `${ctx}: Invalid mapping: a 'render'-key is present, this is probably a bug: ${JSON.stringify(mapping)}`
}
if (typeof mapping.if !== "string" && mapping.if["length"] !== undefined) {
throw `${ctx}: Invalid mapping: "if" is defined as an array. Use {"and": <your conditions>} or {"or": <your conditions>} instead`