Skip to content

Commit

Permalink
fix: throw a more useful error when template does not contain a model
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkpunkd committed Dec 18, 2019
1 parent 4371d8a commit 1753029
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/rundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} = {}
Expand Down Expand Up @@ -315,6 +321,6 @@ ${entries}

async isActive (): Promise<boolean> {
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'
}
}

0 comments on commit 1753029

Please sign in to comment.