Improve error messages

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

View file

@ -286,7 +286,7 @@ export class TagUtils {
private static TagUnsafe(json: AndOrTagConfigJson | string, context: string = ""): TagsFilter {
if (json === undefined) {
throw `Error while parsing a tag: 'json' is undefined in ${context}. Make sure all the tags are defined and at least one tag is present in a complex expression`
throw new Error(`Error while parsing a tag: 'json' is undefined in ${context}. Make sure all the tags are defined and at least one tag is present in a complex expression`)
}
if (typeof (json) != "string") {
if (json.and !== undefined && json.or !== undefined) {

View file

@ -226,7 +226,7 @@ export class Fuse<T> extends DesugaringStep<T> {
break;
}
}catch(e){
console.error("Step "+step.name+" failed due to "+e);
console.error("Step "+step.name+" failed due to ",e,e.stack);
throw e
}
}

View file

@ -321,8 +321,9 @@ export class DetectShadowedMappings extends DesugaringStep<QuestionableTagRender
for (const calculatedTagName of this._calculatedTagNames) {
defaultProperties[calculatedTagName] = "some_calculated_tag_value_for_"+calculatedTagName
}
const parsedConditions = json.mappings.map(m => {
const ifTags = TagUtils.Tag(m.if);
const parsedConditions = json.mappings.map((m,i) => {
const ctx = `${context}.mappings[${i}]`
const ifTags = TagUtils.Tag(m.if, ctx);
if(m.hideInAnswer !== undefined && m.hideInAnswer !== false && m.hideInAnswer !== true){
let conditionTags = TagUtils.Tag( m.hideInAnswer)
// Merge the condition too!
@ -407,7 +408,7 @@ export class DetectMappingsWithImages extends DesugaringStep<TagRenderingConfigJ
const mapping = json.mappings[i]
const ignore = mapping["#"]?.indexOf(ignoreToken) >=0
const images = Utils.Dedup(Translations.T(mapping.then).ExtractImages())
const images = Utils.Dedup(Translations.T(mapping.then)?.ExtractImages() ?? [])
const ctx = `${context}.mappings[${i}]`
if (images.length > 0) {
if(!ignore){

View file

@ -287,7 +287,7 @@ export interface LayerConfigJson {
*/
tagRenderings?:
(string
| { builtin: string, override: any }
| { builtin: string | string[], override: any }
| QuestionableTagRenderingConfigJson
| RewritableConfigJson<(string | { builtin: string, override: any } | QuestionableTagRenderingConfigJson)[]>
) [],

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`