From 175302940f6ea6496d17567e83f419947c0289be Mon Sep 17 00:00:00 2001 From: Richard Cartwright Date: Wed, 18 Dec 2019 12:38:37 +0000 Subject: [PATCH] fix: throw a more useful error when template does not contain a model --- src/rundown.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rundown.ts b/src/rundown.ts index 0d486fa..dc35708 100644 --- a/src/rundown.ts +++ b/src/rundown.ts @@ -94,7 +94,13 @@ export class Rundown implements VRundown { } let template = await this.getTemplate(nameOrID) // console.dir((template[nameOrID] as any).model_xml.model.schema[0].fielddef, { depth: 10 }) - let fielddef = (template as any).model_xml.model.schema[0].fielddef + let fielddef + if (template.hasOwnProperty('model_xml') && typeof template.model_xml === 'object' && + template.model_xml.hasOwnProperty('model') && typeof template.model_xml.model === 'object') { + fielddef = (template as any).model_xml.model.schema[0].fielddef + } else { + throw new Error(`Could not retrieve field definitions for tempalte '${nameOrID}'. Not creating element '${elementNameOrChannel}'.`) + } let fieldNames: string[] = fielddef ? fielddef.map((x: any): string => x.$.name) : [] let entries = '' let data: { [ name: string ]: string} = {} @@ -315,6 +321,6 @@ ${entries} async isActive (): Promise { let playlist = await this.mse.getPlaylist(this.playlist) - return typeof playlist.active_profile.value !== 'undefined' + return playlist.active_profile && typeof playlist.active_profile.value !== 'undefined' } }